log using funeral.log, replace set more off set mem 500m ** by Jean Roth, jroth@nber.org , 2009-07-16 *use newid ucc 2005/sas/Intrvw05/mtbi061.dta *describe *count if ucc=="680140" *use newid ref_race using 2005/sas/Intrvw05/fmli051.dta program loop ***************************************************** ** Getting data set name from full path and file name set obs 1 gen j="`1'" gen year=substr(j,1,4) gen yr=substr(year,3,2) gen r=reverse(j) gen i=index(r,"/") quietly sum i local i = `r(mean)'-1 gen s=substr(r,1,`i') gen c=reverse(s) gen m=subinstr(c,".dta","",1) gen e=subinstr(m,"x","",1) gen f=subinstr(e,"mtbi","fmli",1) local m = m[1] di "m=`m'" local f = f[1] di "f=`f'" clear ***************************************************** *use newid ucc using `1' if ucc=="680140" use newid ucc cost ref_yr using `1' describe sort newid save /tmp/`m', replace clear use newid ref_race using "`2'" sort newid merge newid using /tmp/`m' *assert _merge==3 tab _merge ** Funerals keep if ucc=="680140" bysort ref_race: sum cost save /tmp/`m', replace clear end loop loop ./2001/intrvw01/mtbi011x.dta ./2001/intrvw01/fmli011x.dta loop ./2001/intrvw01/mtbi012.dta ./2001/intrvw01/fmli012.dta loop ./2001/intrvw01/mtbi013.dta ./2001/intrvw01/fmli013.dta loop ./2001/intrvw01/mtbi014.dta ./2001/intrvw01/fmli014.dta ***loop ./2001/intrvw01/mtbi021.dta ./2002/intrvw02/fmli021.dta loop ./2002/intrvw02/mtbi021x.dta ./2002/intrvw02/fmli021x.dta loop ./2002/intrvw02/mtbi022.dta ./2002/intrvw02/fmli022.dta loop ./2002/intrvw02/mtbi023.dta ./2002/intrvw02/fmli023.dta loop ./2002/intrvw02/mtbi024.dta ./2002/intrvw02/fmli024.dta ***loop ./2002/intrvw02/mtbi031.dta loop ./2003/Intrvw03/mtbi031x.dta ./2003/Intrvw03/fmli031x.dta loop ./2003/Intrvw03/mtbi032.dta ./2003/Intrvw03/fmli032.dta loop ./2003/Intrvw03/mtbi033.dta ./2003/Intrvw03/fmli033.dta loop ./2003/Intrvw03/mtbi034.dta ./2003/Intrvw03/fmli034.dta **loop ./2003/Intrvw03/mtbi041.dta loop ./2004/Intrvw04/mtbi041x.dta ./2004/Intrvw04/fmli041x.dta loop ./2004/Intrvw04/mtbi042.dta ./2004/Intrvw04/fmli042.dta loop ./2004/Intrvw04/mtbi043.dta ./2004/Intrvw04/fmli043.dta loop ./2004/Intrvw04/mtbi044.dta ./2004/Intrvw04/fmli044.dta *loop ./2004/Intrvw04/mtbi051.dta loop ./2005/sas/Intrvw05/mtbi051x.dta ./2005/sas/Intrvw05/fmli051x.dta loop ./2005/sas/Intrvw05/mtbi052.dta ./2005/sas/Intrvw05/fmli052.dta loop ./2005/sas/Intrvw05/mtbi053.dta ./2005/sas/Intrvw05/fmli053.dta loop ./2005/sas/Intrvw05/mtbi054.dta ./2005/sas/Intrvw05/fmli054.dta **loop ./2005/sas/Intrvw05/mtbi061.dta use /tmp/mtbi051x, clear append using /tmp/mtbi052 append using /tmp/mtbi053 append using /tmp/mtbi054 append using /tmp/mtbi041x append using /tmp/mtbi042 append using /tmp/mtbi043 append using /tmp/mtbi044 append using /tmp/mtbi031x append using /tmp/mtbi032 append using /tmp/mtbi033 append using /tmp/mtbi034 append using /tmp/mtbi021x append using /tmp/mtbi022 append using /tmp/mtbi023 append using /tmp/mtbi024 append using /tmp/mtbi011x append using /tmp/mtbi012 append using /tmp/mtbi013 append using /tmp/mtbi014 bysort ref_race: sum cost