global year : env YEAR * this turn on/off processing of life tables for Non-Hispanic/Hispanic groups because they might not be available for all years global hispdata : env HISPDATA log using cdc_nvsr_lifetables$year.log, replace include ../../../fem_env.do * shall we process the life tables for Hispanic/Non-Hispanic groups? local racelist black white if $hispdata==1 { local racelist `racelist' nhblack nhwhite hispanic } * Prepare CDC period life table for this year foreach sex in male female { use $outdata/cdc_life_tables/`sex'$year.dta ** manually correct a typo in some years of the CDC tables replace C1 = "79-80" if inlist($year,2001,2002,2003,2004) & strpos(C1,"70-80")==1 tempfile `sex'$year gen age = . forvalues i=0/100 { replace age = `i' if strpos(C1, "`i'")==1 } drop if missing(age) gen black = . gen male = "`sex'"=="male" destring C2 C3 C4 C5 C6 C7, gen(qx lx dx Lx Tx ex) keep age black male qx lx dx Lx Tx ex gen year=$year save ``sex'$year' foreach race in `racelist' { use $outdata/cdc_life_tables/`race'_`sex'$year.dta ** manually correct a typo in some years of the CDC tables replace C1 = "79-80" if inlist($year,2001,2002,2003,2004) & strpos(C1,"70-80")==1 tempfile `race'_`sex'$year gen age = . forvalues i=0/100 { replace age = `i' if strpos(C1, "`i'")==1 } drop if missing(age) if "`race'" != "nhblack" & "`race'" != "nhwhite" & "`race'" != "hispanic" { gen black = "`race'"=="black" } if "`race'" != "black" & "`race'" != "white" { gen nhblack = "`race'"=="nhblack" gen hispanic = "`race'"=="hispanic" } gen male = "`sex'"=="male" destring C2 C3 C4 C5 C6 C7, gen(qx lx dx Lx Tx ex) gen year=$year save ``race'_`sex'$year' } } clear append using `black_female$year' `black_male$year' `white_female$year' `white_male$year' `nhblack_female$year' `nhblack_male$year' `nhwhite_female$year' `nhwhite_male$year' `hispanic_female$year' `hispanic_male$year' `female$year' `male$year' local racekeeplist black if $hispdata==1 { local racekeeplist `racekeeplist' nhblack hispanic } keep year age `racekeeplist' male qx lx dx Lx Tx ex sort black male age label var qx "Probablity of dying between ages x to x+1" label var lx "Number surviving to age x" label var dx "Number dying between ages x to x+1" label var Lx "Person-years lived between ages x to x+1" label var Tx "Total number of person-years lived above age x" label var ex "Expectation of life at age x" label var black "Black (includes Hispanic)" if $hispdata==1 { label var nhblack "Non-Hispanic Black" label var hispanic "Hispanic" } save $indata/cdc_nvsr_lifetable$year.dta, replace