/*File to fix the IHIS year and quarter data back to its original format and generate new NHISID variables*/ clear clear matrix clear mata set logtype text set mem 8g set more off log using FixIHIS_pre1967.txt, replace use ihis_00006.dta, clear preserve keep if year>1967 save after1967.dta, replace restore keep if year<1968 gen imp_year=substr(nhispid,1,4) destring imp_year, replace gen imp_quarter=substr(nhispid,5,1) destring imp_quarter, replace gen imp_psurandr=substr(nhispid,6,3) gen imp_week=substr(nhispid,9,2) gen imp_segment=substr(nhispid,11,2) gen imp_hhid=substr(nhispid,13,2) gen imp_person=substr(nhispid,15,2) gen year2=year replace year2=year+1 if imp_quarter>2 *gen quarter2=imp_quarter gen quarter2=1 if imp_quarter==3 replace quarter2=2 if imp_quarter==4 replace quarter2=3 if imp_quarter==1 replace quarter2=4 if imp_quarter==2 gen str year3=string(year2, "%04.0f") gen str quarter3=string(quarter2, "%01.0f") egen nhispid2=concat(year3 quarter3 imp_psurandr imp_week imp_segment imp_hhid imp_person) replace nhispid=nhispid2 replace year=year2 replace quarter=quarter2 drop imp_* quarter2 year2 year3 quarter3 nhispid2 save pre1967.dta, replace append using after1967.dta save newihis.dta, replace log close