Derivation
variable: dthlftyy [year of death or departure] (table[s]: indices)
variable: outcomdate [outcome date] (table[s]: tbfu_stata)
variable: adl [status: alive/dead/left] (table[s]: indices, tbfu_stata, tb_tbfu)
variable: intdate [date of interview] (table[s]: indices)
variable: dthdate [date of death] (table[s]: tb_tbfu)
variable: leftdate [date of departure] (table[s]: tb_tbfu)
variable: alivedate [date last known alive] (table[s]: tb_tbfu)
<the follow up data is created separately:>
use ${newstata}\indices, clear
recode dthlftyy 0/1900=. 9999=.
gen outcomdate=mdy(6,15,dthlftyy)
drop crsno
append using ${newstata}\tbfu_stata
gen dthdate=outcomdate if adl==2 //2=died
gen leftdate=outcomdate if adl==3 //3=left
append using ${newstata}\tb_tbfu
drop if adl==8 //8=unknown
replace intdate=. if dthdate~=. | leftdate~=. | alivedate~=.
egen lastdate=rowmax(intdate dthdate leftdate alivedate)
bys ident: egen lastfudate=max(lastdate)
gen lastadl=adl if lastdate==lastfudate
bys ident: egen lastfuoutcome=max(lastadl)
la val lastfuoutcome adl
keep ident lastfudate lastfuoutcome
format %td lastfudate
duplicates drop
save ${tempfiles}\fu_dates, replace
<then merged into the main data file:>
merge m:1 ident using ${tempfiles}\fu_dates, keep(master match) nogen