Thursday, August 09, 2007

Computing Sample mean, standard errors & design effects in Stata

Stata has a package for survey sampling: svy. Here are steps to get sample mean, standard errors and design effects in Stata.


1. Declare sample design (weight, primary sampling units, strata, etc)

*stata 8.2
svyset [pweight=factor], psu(psuid) strata(strataid)

*stata 9 or 10
svyset upm [pweight=factor], strata(strataid)

2. Compute sample mean, standard errors & design effects

*stata 8.2
svymean income
gen sigma = sqrt(e(N) * el(e(V_srs),1,1))
svymean income, by(sex)
gen sigma1 = sqrt(el(e(_N),1,1) * el(e(V_srs),1,1))
gen sigma2 = sqrt(el(e(_N),1,2) * el(e(V_srs),2,2))

*version 9
svy: mean income
estat sd
estat effect *design effect
svy: mean income, over(sex)
estat sd
estat effect

The design effect is correct in stata 8.2 using svymean. But it is wrong in stata 9 or 10 using svy: mean. We have to use estat effect to get correct design effect in stata 9 or 10.

No comments: