Stata svy:mean Command for Means

Statements

Explanation

use "C:\Stata\tutorial\analysis_data.dta", clear

 

Use the use command to load the Stata-format dataset. Use the clear option to replace any data in memory.

svyset [w=wtmec4yr], psu(sdmvpsu) strata(sdmvstra) vce(linearized)

                                            

 

Use the svyset command to declare the survey design for the dataset. Specify the psu variable sdmvpsu. Use the [w=] option to account for the unequal probability of sampling and non-response.  In this example, the MEC weight for four years of data (wtmec4yr) is used because this analysis uses 4 years pf data and blood pressure measurements were done in the MEC. Use the strata ( ) option to specify the stratum identifier (sdmvstra). Use the vce( ) option to specify the variance estimation method  (linearized) for Taylor linearization. This is the default method if the option is not specified.

svy: mean bpxsar, subpop(if ridageyr>=20 & ridageyr<.)

 

Use the svy : mean command  with the systolic blood pressure variable (bpxsar) to estimate the mean systolic blood pressure for people age 20 years and older. Use the subpop( ) option to select a subpopulation for analysis, rather than select the study population in the Stata program while preparing the data file. This example uses an if statement to define the subpopulation based on the age variable's (ridageyr) value. Another option is to create a dichotomous variable where the subpopulation of interest is assigned a value of 1, and everyone else is assigned a value of 0.

estat size, obs size

Use the estate size post estimation command to display the number of subpopulation observations and weighted numbers.

svy: mean bpxsar, subpop(if ridageyr>=20 & ridageyr<.) over(riagendr)

 

Use the svy : mean command  with the systolic blood pressure variable (bpxsar) to estimate the mean systolic blood pressure for people age 20 years and older. Use the subpop( ) option to select a subpopulation for analysis, rather than select the study population in the Stata program while preparing the data file. This example uses an if statement to define the subpopulation based on the age variable's (ridageyr) value. Another option is to create a dichotomous variable where the subpopulation of interest is assigned a value of 1, and everyone else is assigned a value of 0. Use the over option to get stratified results. This example produces estimates by gender.

estat size, obs size

Use the estate size post estimation command to display the number of subpopulation observations and weighted numbers.

lincom [bpxsar]male - [bpxsar]female

 

OR

svy: reg bpxsar ridagendr

Use the lincom  post estimation command to test the hypothesis that the difference between mean SBP (bpxsar) for males and females equal 0. This command can only be used after you have done some estimating (e.g. means, regression, etc...). Use square brackets around the variable you are estimating. After the variables in square brackets, put the stratifier that you want to test (e.g. the variable in the over option). This example uses labeled values (male, female) instead of the coded values (1,2) for the gender variable (riagendr).

The svy:reg command could also be used to test the hypothesis that the difference between mean SBP (bpxsar) for males and females equal 0. This command can be used without prior estimation.