For some strange reason, the classical sample size for single proportion is not that intuitive in Stata. There is a user written command, svysampsi that works but I found the mix of proportions and prevalecne that it expects to be a bit much. Further it does include design effects.
As an epidemiologist, I think in terms of Prevalence percentages, relative errors and percentage response rates when I am thinking about sample sizes for single sampel prevalence.
// FIRST INSTALL svysampsi as a one time package
ssc install svysampsi
Code language: Stata (stata)
So I have written this program that acts as a wrapper around the ‘svysampsi’ commands.
Here it goes
*** ESTIMATE SAMPLE SIZE for Proportions
cap prog drop ssSurvey
program define ssSurvey
args prevPercent margErrorPer responsePer designEffect fpcSize
* local prevPercent = 000.09452
* local margErrorPer= 25
* local responsePer = 85
* local fpcSize = 1000000
local responseProp = `responsePer' /100
local prevProp = `prevPercent'/100
local moe = `prevProp'* `margErrorPer'
// di as input _newline(1) "Prevalence % =" `prevPercent' " % which is Equal to proprotion = " `prevProp'
// di "Absolute error at `margErrorPer'% Relative Error = " `prevProp'* `margErrorPer' "% or" `moe'
di as error "Estimating Sample size"
qui svysampsi `fpcSize', prop(`prevProp') moe(`moe') lev(95) response(`responseProp')
di as text _newline(1) "Sample size = " as result round(r(resp_adjss) * `designEffect') as text _newline(1)" For "
di as text " Prevalence = " as result `prevPercent' "%
di as text " Relative Error = " as result r(moe)*100 / r(prop) "%" as text " Abs error = " as result r(moe)*100 "%"
di as text " Response Rate = " as result r(resp)*100 "%" as text " and 95% Confidence"
di as text " Design Effect = " as result `designEffect'
end
Code language: Stata (stata)
Usage
It takes four arguments, inorer of sequence
- Prevalence expressed as (%)
- Relative error expressed as percentage (%)
- Response rate expressed as percentage (%)
- design effect expressed as a multiplier
- Finite population correction – – keep it at one million for large sizes
Example
ssSurvey 0.0955 25 85 1.5 1000000
Code language: Stata (stata)
Result
Estimating Sample size
Sample size = 106613
For
Prevalence = .0955%
Relative Error = 25% Abs error = .023875%
Response Rate = 85% and 95% Confidence
Design Effect = 1.5
.
end of do-file
Code language: Stata (stata)