clear all set more off set maxvar 10000 *Set path *** *cd ---- specify path to \data_replication\psid\ local procdata "./proc_data/" local rawdata "./raw_data/" cd proc_data use for_reg.dta, clear *Prepare the panel drop if age<25 & year==1999 drop if age>85 & year==2011 bys hid: gen nyear=[_N] keep if nyear==7 keep fam_ID year hid save income_panel2.dta, replace cd .. *############################################################################### *Prepare the refinancing data for each year *############################################################################### foreach x of numlist 99 01 03 05 07 09 11{ clear *############################################################################### *Prepare the consumption data *############################################################################### if `x'==99 | `x'==11{ *Convert PSID consumption files to stata format cd raw_data do CON`x'.do ren CON`x'_ID fam_ID if `x'==99 { gen year=19`x' *join with income cd .. joinby fam_ID year using `procdata'income_panel2.dta, unmatched(both) drop if _merge!=3 drop _merge save `procdata'cons_temp19`x'.dta,replace } else{ gen year=20`x' *join with income cd .. joinby fam_ID year using `procdata'income_panel2.dta, unmatched(both) drop if _merge!=3 drop _merge save `procdata'cons_temp20`x'.dta,replace } } else{ *Convert PSID consumption files to stata format cd raw_data do CON0`x'.do ren CON0`x'_ID fam_ID gen year=200`x' *join with income cd .. joinby fam_ID year using `procdata'income_panel2.dta, unmatched(both) drop if _merge!=3 drop _merge save `procdata'cons_temp200`x'.dta,replace } } cd proc_data *Create consumption variables for each year *note that some files contain more variables *1999 use cons_temp1999.dta, clear gen food_cons=FOOD99 gen rent_cons=RENT99 gen util_cons=UTIL99 gen tran_cons=TRAN99 gen educ_cons=ED99 gen kids_cons=CHILD99 gen heal_cons=HEALTH99 keep food_cons rent_cons util_cons tran_cons educ_cons kids_cons heal_cons hid year save cons1999.dta, replace *2001 and 2003 forval x=2001(2)2003{ local i=`x'-2000 use cons_temp200`i'.dta, clear gen food_cons=FOOD0`i' gen rent_cons=RENT0`i' gen util_cons=UTIL0`i' gen tran_cons=TRAN0`i' gen educ_cons=ED0`i' gen kids_cons=CHILD0`i' gen heal_cons=HEALTH0`i' keep food_cons rent_cons util_cons tran_cons educ_cons kids_cons heal_cons hid year save cons`x'.dta, replace } *2005,2007 and 2009 forval x=2005(2)2009{ local i=`x'-2000 use cons_temp200`i'.dta, clear gen food_cons=FOOD0`i' gen rent_cons=RENT0`i' gen util_cons=UTIL0`i' gen tran_cons=TRAN0`i' gen educ_cons=ED0`i' gen kids_cons=CHILD0`i' gen heal_cons=HEALTH0`i' gen other_cons=TELINT0`i'+CLOTH0`i'+TRIPS0`i'+OTHREC0`i' keep food_cons rent_cons util_cons tran_cons educ_cons kids_cons heal_cons hid year other_cons save cons`x'.dta, replace } *2011 use cons_temp2011.dta, clear gen food_cons=FOOD11 gen rent_cons=RENT11 gen util_cons=UTIL11 gen tran_cons=TRAN11 gen educ_cons=ED11 gen kids_cons=CHILD11 gen heal_cons=HEALTH11 gen other_cons=TELINT11+CLOTH11+TRIPS11+OTHREC11 keep food_cons rent_cons util_cons tran_cons educ_cons kids_cons heal_cons hid year other_cons save cons2011.dta, replace