Derivation
variable: trtest [decade estimate of contact treatment start date] (table[s]: tb_contact, tb_contactto2007, tbold_contact)
variable: trtmm [month of contact treatment start date] (table[s]: tb_contact, tb_contactto2007, tbold_contact)
variable: trtyear [year of contact treatment start date] (table[s]: tb_contact, tb_contactto2007, tbold_contact)
variable: trtdate [date of contact treatment start date] (table[s]: tb_contact, tb_contactto2007, tbold_contact)
<the exposure contacts are processed separately first:>
replace trtyear=1905 if trtest==2
replace trtyear=1915 if trtest==3
replace trtyear=1925 if trtest==4
replace trtyear=1935 if trtest==5
replace trtyear=1945 if trtest==6
replace trtyear=1955 if trtest==7
replace trtyear=1965 if trtest==8
replace trtyear=1975 if trtest==9
replace trtyear=1985 if trtest==10
replace trtyear=1995 if trtest==11
recode trtyear 9999=.
gen trtdate=mdy(trtmm,15,trtyear) if trtmm~=. & trtyear~=.
replace trtdate=mdy(6,15,trtyear) if trtmm==. & trtyear~=.reshape wide idcontac famcont contvil contplace trtdate trtdatex trtplace certtbcon wardvisit relship contaccon cough nurseill houseill sleepill contacind contaclong contacdays, i(ident frm_intdate) j(n)
rename * c*
rename (cident cidcontac* cfrm_intdate cnumtbcont) (ident idcontac* intdate numtbcont)
save ${tempfiles}\tbcontacts_wide, replace
<and then merged into the main file:>
merge m:1 ident intdate using ${tempfiles}\tbcontacts_wide, keep(master match) nogen