Stata Commands for Generating Prevalence Rates

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 specific the variance estimation method  (linearized) for Taylor linearization.
quietly svy, subpop(if ridageyr >=20 & ridageyr <.): mean hbpx

estate size

parmest, saving("c:\NHANES\Data\popmean1", replace)

Use the prefix quietly before the svy command to suppress terminal output. Use the svy : mean command  with the high blood pressure variable (hbpx) to estimate the prevalence of HBP. 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 estate size post estimation command to display subpopulation sizes.

Use the parmest command with the saving option to create a new Stata dataset of the most recently requested parameter estimates.

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

estate size

parmest, saving("c:\NHANES\Data\popmean2", replace)

Use the prefix quietly before the svy command to suppress terminal output. Use the svy : mean command  with the high blood pressure variable (hbpx) to estimate the prevalence of HBP. 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.  In this example, gender (riagendr) is of interest.

 Use the estate size post estimation command to display subpopulation sizes. Use the parmest command with the saving option to create a new Stata dataset of the most recently requested  parameter estimates.

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

estate size

parmest, saving("c:\NHANES\Data\popmean3", replace)

Use the prefix quietly before the svy command to suppress terminal output. Use the svy : mean command  with the high blood pressure variable (hbpx) to estimate the prevalence of HBP. 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 cross-tabulations for estimates requested.  In this example, race-ethnicity (race) is of interest.

Use the estate size post estimation command to display subpopulation sizes.

Use the parmest command with the saving option to create a new Stata dataset of the most recently requested  parameter estimates.

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

estate size

parmest, saving("c:\NHANES\Data\popmean4", replace)

Use the prefix quietly before the svy command to suppress terminal output. Use the svy : mean command  with the high blood pressure variable (hbpx) to estimate the prevalence of HBP. 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 cross-tabulations for estimates requested.  In this example, gender (riagendr), and race-ethnicity (race) are of interest.

Use the estate size post estimation command to display subpopulation sizes.

Use the parmest command with the saving option to create a new Stata dataset of the most recently requested  parameter estimates.

 

 

Create Race and Gender Variables from Stata Parameters Output Dataset

Statements Explanation
use "c:\NHANES\Data\popmean1", clear

gen riagendr=0 

gen race=0

drop parm

save "c:\NHANES\Data\popmean1", replace

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

Use the generate (gen) command to create gender (riagendr) and race variables equal to 0 to indicate all genders and races. Use the drop command to remove the parm variable.

Use the save command to save the dataset.

use "c:\NHANES\Data\popmean2", clear

gen riagendr=1 if parm=="male"

replace riagendr=2 if parm=="female"

gen race=0

drop parm

save "c:\NHANES\Data\popmean2", replace

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

Use the generate (gen) and replace commands to create gender (riagendr) equal 1 (male) and 2 (female) and race equal 0 for all races. Use the drop command to remove the parm variable.

Use the save command to save the dataset.

use "c:\NHANES\Data\popmean3", clear

gen riagendr=0

gen race=1 if parm=="_subpop_1"

replace race=2 if parm=="_subpop_2"

replace race=3 if parm=="_subpop_3"

replace race=4 if parm=="_subpop_4"

drop parm

save "c:\NHANES\Data\popmean3", replace

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

Use the generate (gen) and replace commands to create race equal 1 (NH White), 2 (NH Black), 3 (Mexican American) and 4 (other races) and riagendr equal to 0 for all genders. Use the drop command to remove the parm variable.

 

Use the save command to save the dataset.

use "c:\NHANES\Data\popmean4", clear

   gen riagendr=1 if parm=="_subpop_1"

| parm== "_subpop_2" | parm== "_subpop_3" | parm== "_subpop_4"

    replace riagendr=2 if parm=="_subpop_5" | parm== "_subpop_6" | parm== "_subpop_7" | parm== "_subpop_8"

    gen race=1 if parm=="_subpop_1" | parm== "_subpop_5"

    replace race=2 if parm=="_subpop_2" | parm== "_subpop_6"

    replace race=3 if parm=="_subpop_3" | parm== "_subpop_7"

    replace race=4 if parm=="_subpop_4" | parm== "_subpop_8"

save "c:\stata\tutorial\age adjustment\popmean4", replace

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

Use the generate (gen) and replace commands to create gender (riagendr) equal 1 (male) and 2 (female) and race equal 1 (Mexican American), 2 (NH White), 3 (NH Black) and 4 (other races). Use the drop command to remove the parm variable.

Use the save command to save the dataset.

use "c:\NHANES\Data\popmean1", clear

     append using
"C:\NHANES\Data\popmean2"

     append using
"C:\NHANES\Data\popmean3"

    append using
"C:\NHANES\Data\popmean4"

sort riagendr race

save "c:\NHANES\Data\popmeans", replace

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

Use the append command to combine all the datasets created above into one dataset.

Use the sort command to sort the variables by gender and race.

Use the save command to save the dataset.

 

 

close window icon Close Window