The examples below use Stata 8. If you are using Stata version 9, please see this page.
This example is taken from Levy and Lemeshow’s Sampling of Populations.
page 285 two-stage cluster sampling (clusters sampled with equal probability)
input center nurse m nbar w npatnts nrefrred
1 2 5 3 2.5 44 6
1 3 5 3 2.5 18 6
2 1 5 3 2.5 42 3
2 3 5 3 2.5 10 2
4 1 5 3 2.5 16 5
4 2 5 3 2.5 32 14
end
svyset [pweight=w], psu(center)
svytotal nrefrred
Survey total estimation
pweight: w Number of obs = 6
Strata: <one> Number of strata = 1
PSU: center Number of PSUs = 3
Population size = 15
------------------------------------------------------------------------------
Total | Estimate Std. Err. [95% Conf. Interval] Deff
---------+--------------------------------------------------------------------
nrefrred | 90 30.31089 -40.41723 220.4172 1.361111
------------------------------------------------------------------------------
svyratio nrefrred npatnts
Survey ratio estimation
pweight: w Number of obs = 6
Strata: <one> Number of strata = 1
PSU: center Number of PSUs = 3
Population size = 15
------------------------------------------------------------------------------
Ratio | Estimate Std. Err. [95% Conf. Interval] Deff
------------------+-----------------------------------------------------------
nrefrred/npatnts | .2222222 .0812779 -.1274883 .5719328 1.33804
------------------------------------------------------------------------------
page 310 two-stage cluster sampling (clusters sampled with equal probability)
use https://stats.idre.ucla.edu/stat/books/sop/i10pt2.dta, clear
svyset psu hospno
svyset pweight w
svytotal dxdead
Survey total estimation
pweight: w Number of obs = 708
Strata: <one> Number of strata = 1
PSU: hospno Number of PSUs = 3
Population size = 23600
------------------------------------------------------------------------------
Total | Estimate Std. Err. [95% Conf. Interval] Deff
---------+--------------------------------------------------------------------
dxdead | 499.3792 114.6776 5.961244 992.7971 .8059769
------------------------------------------------------------------------------
svyratio dxdead lifethrt
Survey ratio estimation
pweight: w Number of obs = 708
Strata: <one> Number of strata = 1
PSU: hospno Number of PSUs = 3
Population size = 23600
------------------------------------------------------------------------------
Ratio | Estimate Std. Err. [95% Conf. Interval] Deff
------------------+-----------------------------------------------------------
dxdead/lifethrt | .1703017 .072273 -.140664 .4812674 3.247372
------------------------------------------------------------------------------
