* SET WORKING DIRECTORIES cd "Working Directory" // BRING IN 2010 DATA AND CLEAN UP import delimited "NGHIS Extract", clear rename h7v001 pop rename h74001 pop18 drop h74* local i = 3 foreach x in white black amin asian nhpi other mult { rename h7z00`i' `x' local i = `i' + 1 } rename h7z010 hisp drop h7z0* *** ensure sums total population gen test = round(white + black + amin + asian + nhpi + other + mult + hisp - pop) assert test == 0 drop test * gq rename h80001 gq rename h80002 gq_inst rename h80007 gq_noninst local i = 3 foreach x in cfa juv nh oth { rename h8000`i' gq_inst_`x' local i = `i' + 1 } rename h80008 gq_noninst_dorm rename h80009 gq_noninst_mil rename h80010 gq_noninst_oth * housing rename ifc001 hu * postfix 2010 renvars pop white black amin asian nhpi other mult hisp pop18 gq gq_inst gq_inst_cfa gq_inst_juv gq_inst_nh gq_inst_oth gq_noninst gq_noninst_dorm gq_noninst_mil gq_noninst_oth hu, postf(2010) keep gisjoin county* tract* block* *2010 rename county coname rename countya county_2010 rename tract tract_2010 rename block blk_2010 save "NAME_block_2010.dta", replace // Create County Totals collapse (sum) pop2010 white2010 black2010 amin2010 asian2010 nhpi2010 other2010 mult2010 hisp2010 pop182010 gq2010 gq_inst2010 gq_inst_cfa2010 gq_inst_juv2010 gq_inst_nh2010 gq_inst_oth2010 gq_noninst2010 gq_noninst_dorm2010 gq_noninst_mil2010 gq_noninst_oth2010 hu2010, by(coname county_2010) save "raw/NAME_cty_2010.dta", replace