/** Compute survival probability in each year of FEM simulation based on CDC life tables */ log using logs/cdc_survival.log, replace * prepare CDC life tables for comparison clear forvalues yr=2004/2016 { append using ../../base_data/cdc_nvsr_lifetable`yr'.dta } desc * only doing gender categories right now drop if !missing(black) | !missing(hispanic) drop if age < 51 | age > 99 gen birthcohort = year - age sort male birthcohort age by male birthcohort: gen survprob = 1.0 if _n==1 by male birthcohort: replace survprob = 1.0 - qx if _n > 1 by male birthcohort: gen cumsurvprob = sum(ln(survprob)) replace cumsurvprob = exp(cumsurvprob) li year birthcohort age qx survprob cumsurvprob * gen pdied2yr_cdc = 1 - (1 - qx[_n-1])*(1 - qx) if mod(year, 2)==0 & age > 51 # 2-year mortality rate = (num. of deaths in years 1 and 2) / (approx. exposure time in years 1 and 2) * gen mx2yr = (dx[_n-1] + (lx[_n-1]*(1-qx[_n-1])*qx)) / (Lx[_n-1] + lx[_n-1]*(1-qx[_n-1])*(1-qx/2)) if mod(year, 2)==0 & age > 55 * drop odd years for merging with FEM results drop if mod(year,2)==1 li year birthcohort age qx survprob cumsurvprob save data/cdc_survival.dta, replace