/** compute mortality rates in HRS (overall and by age) numerator = Rs who died during a year denominator = Rs who were alive in a year: entered sample in this year or earlier and died after this year or never died Rs who died with no death date are dropped 1. find year of first wave after entry 2. find death year 3. for those with missing death date who left sample, find last interview year 4. make person-year observations during time in HRS sample, with flag in last year for death 5. summarize */ set maxvar 15000 global firstwave 1 global lastwave 12 local fixvars hhidpn ranyear radyear randatef raidatef * load RAND HRS keeping only necessary variables use /sch-data-library/public-data/HRS/Unrestricted/RAND-HRS/rndhrs_p.dta, clear keep `fixvars' r*iwstat r*wtresp r*iwbeg r*iwend * find first year in sample gen firstyr = 30000 forvalues i = $firstwave(1)$lastwave { local year = 1990 + 2*`i' di "wave `i' year `year'" replace firstyr = `year' if inlist(r`i'iwstat,1,4,5) & `year' < firstyr } * find last year in sample gen lastyr = 1000 gen lastwtyr = 1000 forvalues i = $lastwave(-1)$firstwave { local year = 1990 + 2*`i' di "wave `i' year `year'" replace lastyr = `year' if inlist(r`i'iwstat,1,4,5) & `year' > lastyr replace lastwtyr = `year' if !missing(r`i'wtresp) & `year' > lastwtyr } count if !missing(radyear) & lastyr + 3 < radyear gen ttd = radyear - lastyr if !missing(radyear) count if !missing(ttd) & ttd < -2 count if !missing(radyear) & radyear - lastwtyr >= 3 /* * keep denominator cases ** drop Rs who haven't entered the sample or already died drop if inlist(iwstat,0,6) * flag numerator cases gen died = iwstat==5 if !missing(iwstat) label var died "died in this wave" * carry last live weight over to death wave sort hhidpn wave replace wtresp = wtresp[_n-1] if died==1 bys wave: count if died==1 & missing(wtresp) * move from waves to years gen year = 1992 + 2*(wave - 1) tab year ** make sure year of death falls within the years for each wave li if died==1 & (radyear < year-1 | radyear > year) expand 2, gen(yroffset) replace year = year - yroffset */