log using "confirmed_cogcat_2006.log", replace *** * product: confirmed_cogcat2006.dta * generate dataset with HRS 2006 confirmed cognitive status with MI for missing TICS, using HRS 2004&2006 data * indata: HRS stock 2006 & HRS analytic recoded; * outdata: HRS 2006 with confirmed cognitive status; sample: HRS 2006 (15,764) * confirmed cognitive status: confirmed AD/MCI/Normal, non-missing * exhibits: as dependent file in: Table1, Table4 * dependent files: none *** /* base data: stock_hrs_2006; select: still alive in wave 8 */ use "../../../input_data/stock_hrs_2006.dta", clear keep if wave==8 keep if iwstat==1 keep if age>=53 keep hhidpn tempfile stock_hrs_2006_id save `stock_hrs_2006_id' use "../../../input_data/hrs_analytic_recoded.dta", clear merge 1:1 hhidpn wave using "../../../input_data/tics.dta", keepusing(totcog cogstate) nogen keep(master match) keep if wave==7|wave==8 merge m:1 hhidpn using `stock_hrs_2006_id' keep if _m!=1 * impute for this wave's TICS gen male_hsless = male*hsless gen male_black = male*black gen male_hispan = male*hispan /* Create age spline indicator variables */ gen l2age = age - 2 gen l2age65l = 63 if 63 < l2age replace l2age65l = l2age if l2age <= 63 gen temp_max = 0 if l2age-63<0 replace temp_max = l2age-63 if l2age-63>0 gen l2age6574 = 10 if 10 < temp_max replace l2age6574 = temp_max if temp_max <= 10 gen l2age75p = 0 if 0 > l2age-73 replace l2age75p = l2age-73 if l2age-73 >= 0 gen weight=. replace weight=wtcrnh if wave<13 replace weight=wtrespe if wave>=13 keep hhidpn wave weight died iwstat totcog black hispan hsless college male male_hsless male_black male_hispan l2age65l l2age6574 l2age75p hearte stroke cancre hibpe diabe lunge hearta work widowed smokev tempfile hrs save `hrs' keep if wave==7 mdesc totcog black hispan hsless college male male_hsless male_black male_hispan l2age65l l2age6574 l2age75p hearte stroke cancre hibpe diabe lunge hearta work widowed smokev mi set wide mi misstable summarize totcog mi register imputed totcog mi impute ologit totcog = black hispan hsless college male male_hsless male_black male_hispan l2age65l l2age6574 l2age75p hearte stroke cancre hibpe diabe lunge hearta work widowed smokev, force add(5) rseed(2020) mi convert mlong, clear * for imputed TICS, keep one ob with mean TICS value drop if _mi_miss==1 gen mi_flag = 0 replace mi_flag = 1 if _mi_m != 0 bys hhidpn wave: egen totcog_mean=mean(totcog) if mi_flag==1 replace totcog=totcog_mean if mi_flag==1 replace totcog=round(totcog,1) drop totcog_mean sort hhidpn wave _mi_m bys hhidpn wave: keep if _n==_N gen cogcat = . replace cogcat = 1 if totcog <= 6 replace cogcat = 2 if totcog >= 7 & totcog <= 11 replace cogcat = 3 if totcog >= 12 & totcog <= 27 mi extract 5, clear tempfile impute7 save `impute7', replace /* wave 8, no imputation for non-responsive in wave 8 (720); died in wave 8(1012) */ use `hrs', clear keep if wave==8 mdesc totcog black hispan hsless college male male_hsless male_black male_hispan l2age65l l2age6574 l2age75p hearte stroke cancre hibpe diabe lunge hearta work widowed smokev mi set wide mi misstable summarize totcog mi register imputed totcog mi impute ologit totcog = black hispan hsless college male male_hsless male_black male_hispan l2age65l l2age6574 l2age75p hearte stroke cancre hibpe diabe lunge hearta work widowed smokev, force add(5) rseed(2020) mi convert mlong, clear * for imputed TICS, keep one ob with mean TICS value drop if _mi_miss==1 gen mi_flag = 0 replace mi_flag = 1 if _mi_m != 0 bys hhidpn wave: egen totcog_mean=mean(totcog) if mi_flag==1 replace totcog=totcog_mean if mi_flag==1 replace totcog=round(totcog,1) drop totcog_mean sort hhidpn wave _mi_m bys hhidpn wave: keep if _n==_N gen cogcat = . replace cogcat = 1 if totcog <= 6 replace cogcat = 2 if totcog >= 7 & totcog <= 11 replace cogcat = 3 if totcog >= 12 & totcog <= 27 mi extract 5, clear tempfile impute8 save `impute8', replace clear use `impute7' append using `impute8' keep totcog cogcat died wave hhidpn weight college hsless xtset hhidpn wave gen l2cogcat = l.cogcat drop if wave==7 gen confirmed_cogcat = . replace confirmed_cogcat = 1 if (l2cogcat==1)&(cogcat==1)|(l2cogcat==1)&(died==1) replace confirmed_cogcat = 2 if ((l2cogcat==2)&(cogcat==2))|((l2cogcat==2)&(cogcat==1))|((l2cogcat==1)&(cogcat==2))|((l2cogcat==2)&(died==1)) replace confirmed_cogcat = 3 if (l2cogcat==3)|((cogcat==3)&!missing(l2cogcat)) xtset, clear gen confirmed_cogcat_hrs2006_nomi = confirmed_cogcat replace confirmed_cogcat_hrs2006_nomi = cogcat if missing(confirmed_cogcat_hrs2006_nomi) keep hhidpn confirmed_cogcat confirmed_cogcat_hrs2006_nomi weight rename confirmed_cogcat confirmed_cogcat_hrs2006 rename weight weight_hrs8 gen confirmed_ad = (confirmed_cogcat_hrs2006_nomi==1) gen confirmed_mci = (confirmed_cogcat_hrs2006_nomi==2) gen confirmed_normal = (confirmed_cogcat_hrs2006_nomi==3) sum confirmed_ad confirmed_mci confirmed_normal [aw=weight_hrs8] save confirmed_cogcat2006.dta, replace log close