The examples below use Stata 7 or 8. If you are using Stata version 9, please see this page.

Here is a tiny example showing how to use the survey commands in Stata. Consider the data file we call

svysmallshown below.

use https://stats.idre.ucla.edu/stat/stata/faq/svysmall, clear listhouse eth wt y x1 x2 x3 1 1 .4 3 4 5 3 1 1 .9 9 4 5 6 2 1 1.2 9 8 7 3 2 1 1 8 7 4 2 2 1 1.1 8 7 6 3 3 2 .8 8 7 3 2 4 2 .4 8 2 0 3 4 2 .7 8 2 5 3

In this tiny example,

houseis the household,ethis the ethnicity, andwtis the weighting for the person. You can use thesvysetcommands to tell Stata about these things and it remembers them. If you save the data file, Stata remembers them with the data file and you don’t even need to enter them the next time youusethe data file. Below, we tell Stata that thepsu(primary sampling unit) is the household (house). Further, the sampling scheme included stratified sampling (strata)based on ethnicity (eth).Finally, the weighting variable (pweight) is calledwt.Note that in Stata versions 6 and 7, you will use the

svysetcommands as shown below. Starting with version 8 of Stata, the way that thesvysetcommand is issued changed. An example is given below.

* Stata 7 commandssvyset psu house svyset strata eth svyset pweight wt* Stata 8 commandsvyset [pweigh=wt], psu(house) strata(eth)

Once Stata knows about the survey via the

svysetcommands, you can use thesvy_____commands using syntax which is quite similar to the non-survey versions of the commands. For example,svyregcommand below looks just like a regularregcommand, but it uses the information you have provided about the survey design and does the computations taking those into consideration.

svyreg y x1 x2 x3

The output is below, and it tells you the

pweight,strata, andpsuvariables so you can confirm the right variables have been chosen.

Survey linear regression pweight: wt Number of obs = 8 Strata: eth Number of strata = 2 PSU: house Number of PSUs = 4 Population size = 6.5000001 F( 1, 2) = 0.35 Prob > F = 0.6135 R-squared = 0.2216 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- x1 | .3321757 .294268 1.129 0.376 -.9339573 1.598309 x2 | -.138397 .2335074 -0.593 0.613 -1.143098 .8663043 x3 | .5504173 .3170068 1.736 0.225 -.8135527 1.914387 _cons | 5.050307 2.040247 2.475 0.132 -3.728167 13.82878 ------------------------------------------------------------------------------