Generate Geometric Means in Stata

Statements Explanation

use
"C:\nhanes\data\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 sdmvpsu [pweight=wtmec4yr], strata(sdmvstra) vce(linearized)

Use the svyset command to declare the survey design for the dataset. Specifiy the psu variable sdmvpsu. Use the [pweight=] 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. Use the strata( ) option to specify the stratum identifier (sdmvstra). Use the vce( ) option to specify the variance estimation method  (linearized) for Taylor linearization.

 

quietly svy, subpop(if ridageyr >=20 & ridageyr <.) vce(linearized): mean log_lbxtc,

ereturn display, eform(geo_mean)

Use the prefix quietly before the svy command to suppress terminal output. Use the svy: mean command  with the total cholesterol variable (lbxtc) to estimate mean total cholesterol. 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. 

Use ereturn display, eform( ) to display the exponentiated coefficients (geo_mean), standard error, and confidence interval of the mean log transformed variable (log_lbxtc).

quietly svy, subpop(if ridageyr >=20 & ridageyr <.) vce(linearized): mean log_lbxtc, over(riagendr)

ereturn display, eform(geo_mean)

 
Use the prefix quietly before the svy command to suppress terminal output. Use the svy: mean command  with the total cholesterol variable (lbxtc) to estimate mean total cholesterol. 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. Use the over( ) option  to specify subgroup tabulations for estimates requested.

Use ereturn display, eform( ) to display the exponentiated coefficients (geo_mean), standard error, and confidence interval of the mean log transformed variable (log_lbxtc).

quietly svy, subpop(if ridageyr >=20 & ridageyr <.) vce(linearized): mean log_lbxtc, over(riagendr age)

ereturn display, eform(geo_mean)

Use the prefix quietly before the svy command to suppress terminal output. Use the svy: mean command  with the total cholesterol variable (lbxtc) to estimate mean total cholesterol. 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. Use the over( ) option  to specify subgroup tabulations for estimates requested.

Use ereturn display, eform( ) to display the exponentiated coefficients (geo_mean), standard error, and confidence interval of the mean log transformed variable (log_lbxtc).