Stata Procedure to Calculate CPS Population Totals

Statements Explanation
use "c:\NHANES\Data\cpstot9902.dta ", clear

collapse (sum) ctutpopt if ctutage >=20,

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

Use the use command to load the Stata-supplied dataset (cpstot9902) to read the CPS population totals.

Use the collapse command to convert the current dataset into a dataset of population total sums for ages greater than or equal to 20 years.

Use the save command to save the dataset.

use "c:\NHANES\Data\cpstot9902.dta", clear

collapse (sum) ctutpopt if ctutage >=20, by(ctutgndr)

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

Use the use command to load the Stata-supplied dataset (cpstot9902) to read the CPS population totals.

Use the collapse command to convert the current dataset into a dataset of population total sums for ages greater than or equal to 20 years by gender.

Use the save command to save the dataset.

use "c:\NHANES\Data\cpstot9902.dta", clear

collapse (sum) ctutpopt if ctutage >=20, by(ctutrace)

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

Use the use command to load the Stata-supplied dataset (cpstot9902) to read the CPS population totals.

Use the collapse command to convert the current dataset into a dataset of population total sums for ages greater than or equal to 20 years by race.

Use the save command to save the dataset.

use "c:\NHANES\Data\cpstot9902.dta", clear

collapse (sum) ctutpopt if ctutage >=20, by(ctutgndr ctutrace)

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

Use the use command to load the Stata-supplied dataset (cpstot9902) to read the CPS population totals.

Use the collapse command to convert the current dataset into a dataset of population total sums for ages greater than or equal to 20 years by gender and race.

Use the save command to save the dataset.

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

append using
   "c:\NHANES\Data\tot9902b"

append using
   "c:\NHANES\Data\tot9902c"

append using
   "c:\NHANES\Data\tot9902d"

rename ctutgndr riagendr

rename ctutrace race

replace riagendr=0 if riagendr==.

replace race=0 if race==.

sort riagendr race

save "c:\NHANES\Data\poptot9902", 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 rename command to change the name of the variables

Use the replace command change the value of the variables from (.) to 0.

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