/** Compute survival distribution for FEM by birth cohort */ global scen : env SCEN log using logs/${scen}_survival.log, replace use ../../output/$scen/${scen}_summary.dta keep year startpop_m_* startpop_f_* n_died_m_* n_died_f_* reshape long startpop n_died, i(year) j(grp) string drop if strlen(grp)!=5 | strmatch("_",substr(grp,3,1))==0 tab grp, m gen male = strmatch("_m_",substr(grp,1,3)) gen age = real(substr(grp,4,2)) desc 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 - n_died / startpop if _n > 1 by male birthcohort: gen cumsurvprob = sum(ln(survprob)) replace cumsurvprob = exp(cumsurvprob) li gen series = "FEM" append using data/cdc_survival.dta data/bellmiller_survival.dta, gen(src) replace series = "CDC" if src==1 replace series = "Bell & Miller" if src==2 keep if year >= 2004 & year <= 2016 & age >= (51 + year - 2004) keep male year age birthcohort cumsurvprob series save data/${scen}_cdc_bellmiller_survival.dta, replace