** by Jean Roth , jroth@nber.org , 2016-01-29 set more off local TYPE hosp local DASH 2552-96 local UNDERSCORE = subinstr("`DASH'","-","_",1) local indir /homes/data/hcris/`DASH' local FIRST_YEAR 2010 local LAST_YEAR 2010 foreach YEAR of num `FIRST_YEAR'/`LAST_YEAR' { ***************************************************************** ***************************************************************** ** Get alphanumeric data use `indir'/`TYPE'_alpha`UNDERSCORE'_`YEAR'_long , clear gen keep = 0 ***************************************************************** ** Specify variables to keep ** Transpose requires A LOT of memory, so just keep the necessary variables replace keep = 1 if wksht_cd == "S000000" & line_num == "00100" & clmn_num == "0200" keep if keep drop keep ***************************************************************** ** Generating wide shape using concatenated id variable gen vvarname = lower(wksht_cd) + "_" + line_num + "_" + clmn_num drop w c l rename *itm* v reshape wide v , i(rpt_rec_num) j(vvarname) string renvars v*, presub(v ) sort rpt_rec_num local DTAALPHA hcris`TYPE'alpha`YEAR' save `DTAALPHA' , replace ***************************************************************** ***************************************************************** ** Get numeric data use `indir'/`TYPE'_nmrc`UNDERSCORE'_`YEAR'_long , clear gen keep = 0 ***************************************************************** ** Specify variables to keep ** Transpose requires A LOT of memory, so just keep the necessary variables replace keep = 1 if wksht_cd == "A000000" & line_num == "00300" & clmn_num == "0200" keep if keep drop keep ***************************************************************** ** Generating wide shape using concatenated id variable gen vvarname = lower(wksht_cd) + "_" + line_num + "_" + clmn_num drop w c l rename *itm* v reshape wide v , i(rpt_rec_num) j(vvarname) string renvars v*, presub(v ) sort rpt_rec_num local DTANUM hcris`TYPE'num`YEAR' save `DTANUM' , replace ***************************************************************** ***************************************************************** merge 1:1 rpt_rec_num using `DTAALPHA' , nogen sort rpt_rec_num duplicates report rpt_rec_num merge 1:1 rpt_rec_num using `indir'/`TYPE'_rpt`UNDERSCORE'_`YEAR' , nogen local DTAEXTRACT hcris`TYPE'extract`YEAR' save `DTAEXTRACT' , replace desc,f }