/** Create a file with gender, race, birthdate, death date */ global rndhrsver : env VERSION log using logs/gen_hrs_analytic_file_$rndhrsver.log, replace set maxvar 15000 if "$rndhrsver"=="P" { use /sch-data-library/public-data/HRS/Unrestricted/RAND-HRS/rndhrs_p.dta, clear } else { use /sch-data-library/public-data/HRS/Unrestricted/RAND-HRS/randhrs1992_2014v3.dta, clear } local inkeeplist raracem ragender rabmonth rabyear raiyear raimonth r*iwstat r*iwbeg racohbyr r*wtresp r*wtcrnh if "$rndhrsver"=="P" { local inkeeplist `inkeeplist' radyear radmonth ranyear ranmonth } keep `inkeeplist' * for missing death months, use June foreach dth in rai ran rad { cap confirm var `dth'month if _rc==0 { replace `dth'month = 6 if !missing(`dth'year) & missing(`dth'month) } } * these are the years when respondents were first eligible for interview gen eligyr = 1993 if racohbyr==1 /* AHEAD */ replace eligyr = 1998 if racohbyr==2 /* CODA */ replace eligyr = 1992 if racohbyr==3 /* HRS */ replace eligyr = 1998 if racohbyr==4 /* WarBabies */ replace eligyr = 2004 if racohbyr==5 /* EBB */ replace eligyr = 2010 if racohbyr==6 /* MBB */ gen insampmo = . gen insampyr = . gen outsampmo = . gen outsampyr = . replace insampyr = eligyr replace insampmo = 1 forvalues i=1/12 { /* * these are the month and year when someone actually had their first interview in sample replace insampmo = month(r`i'iwbeg) if insampmo==. & year(r`i'iwbeg) >= eligyr & r`i'iwstat==1 & !missing(r`i'iwbeg) replace insampyr = year(r`i'iwbeg) if insampyr==. & year(r`i'iwbeg) >= eligyr & r`i'iwstat==1 & !missing(r`i'iwbeg) */ * these are the last year that a person responded in the sample or the year that they died if they died in the wave following a live interview * the goal is to track the time that a respondent is eligible for the FEM mortality model estimation sample replace outsampmo = month(r`i'iwbeg) if r`i'iwstat==1 & !missing(r`i'iwbeg) replace outsampyr = year(r`i'iwbeg) if r`i'iwstat==1 & !missing(r`i'iwbeg) if `i' > 1 { local lagwv = `i' - 1 replace outsampmo = raimonth if raiyear != .x & inlist(r`i'iwstat,2,3,5) & r`lagwv'iwstat==1 replace outsampyr = raiyear if raiyear != .x & inlist(r`i'iwstat,2,3,5) & r`lagwv'iwstat==1 } } replace outsampmo = raimonth if raimonth != .x replace outsampyr = raiyear if raiyear != .x * create the last weight assigned to a person before the start of a calendar year forvalues yy=2001/2012 { local lastwv = ceil((`yy' - 1992)/2) gen wtbeg`yy' = r`lastwv'wtcrnh * set the weight to zero in years after they died replace wtbeg`yy' = 0.0 if !missing(wtbeg`yy') & wtbeg`yy' > 0.0 & !missing(raiyear) & raiyear < `yy' label var wtbeg`yy' "Last weight assigned before start of `yy'" } gen male = ragender==1 if !missing(ragender) gen black = raracem==2 if !missing(raracem) & raracem!=3 * drop if missing(male) | missing(black) local outkeeplist male black rabmonth rabyear raiyear raimonth insampyr insampmo outsampyr outsampmo wtbeg* if "$rndhrsver"=="P" { local outkeeplist `outkeeplist' radyear radmonth ranmonth ranyear } keep `outkeeplist' sort black male save data/hrs_analytic_$rndhrsver.dta, replace exit, clear