*quietly include common.do quietly include "../../../fem_env.do" * SSA Trustees Report table from which we are pulling mortality assumptions (just the file name without ".dta") global ssatable : env SSATABLE log using mortality_assumptions_$ssatable.log, replace * This is the reference (normalized value = 1) year for the series - should be the midpoint of mortality estimation global ref_yr : env REFYEAR * This is the first year in the series -- the earliest year at which a simulation can start using this series global start_yr : env STARTYEAR use $indata/$ssatable.dta, replace * special handling for 2013 table which uses "ageadjusted" instead of "agesexadjusted" in variable names cap confirm var under65ageadjusteddeathrate if _rc==0 { keep year under65ageadjusteddeathrate andoverageadjusteddeathrate rename under65ageadjusteddeathrate under65DR rename andoverageadjusteddeathrate over65DR } else { keep year under65agesexadjusteddeathrate andoveragesexadjusteddeathrate rename under65agesexadjusteddeathrate under65DR rename andoveragesexadjusteddeathrate over65DR } keep if year >= $start_yr * Populate the missing years in the table sort year expand year[_n+1] - year if _n < _N, gen(missyear) li sort year missyear replace year = _n + $start_yr - 1 li replace under65DR = . if missyear==1 replace over65DR = . if missyear==1 * Interpolate using cubic splines through the end of the table csipolate under65DR year, gen(cs_u65) csipolate over65DR year, gen(cs_o65) replace under65DR = cs_u65 if under65DR == . replace over65DR = cs_o65 if over65DR == . * Populate values for years after end of table until 2150 expand 2150-year+1 if _n==_N bys year: replace under65DR = . if _n > 1 bys year: replace over65DR = . if _n > 1 bys year: replace year = year + _n - 1 * Interpolate using GLM with a log link - SSA assumptions are for smooth decrease in mortality after 2012 ... curve is smoother starting later in year glm under65DR year if year >= 2040, link(log) predict p_under65DR glm over65DR year if year >= 2040, link(log) predict p_over65DR replace under65DR = p_under65DR if under65DR == . replace over65DR = p_over65DR if over65DR == . * Scale the results relative to ref_yr local ref_obs = $ref_yr - $start_yr + 1 sort year gen rate_under65 = under65DR/under65DR[`ref_obs'] gen rate_over65 = over65DR/over65DR[`ref_obs'] * keep if mod(year,2) > 0 keep year rate_under65 rate_over65 reshape long rate, i(year) j(agecat) string gen l2age65pd = agecat=="_over65" if !missing(agecat) drop agecat sort l2age65pd year order l2age65pd year rate *save $outdata/mortality_assumptions_${ssatable}_ref${ref_yr}_start$start_yr.dta, replace export delimited using $outdata/mortality_assumptions_${ssatable}_ref${ref_yr}_start$start_yr.txt, delimiter(tab) replace /* preserve drop over65DR_rate save $outdata/mortality_adj_u65_start$start_yr_$ssatable.dta, replace restore drop under65DR_rate save $outdata/mortality_adj_65p_start$start_yr_$ssatable.dta, replace */ capture log close