/**************
* derived from the "blocktables" do-files,
* this is county-level analysis.
* FILE 1: MAIN SPECIFICAITON, PRIMARY SAMPLE
***************/
version 11
capture log close
log using "$output/table2_final_r3.xls.txt", replace
	
use "$data2/poverty_full_county2", clear
local outopts "bracket label bdec(2)"
keep if sample1==1		// All counties except AK, HI, DC, two problem cos. in AR
local samplenum=1		//number sample in outreg files

if `samplenum'==1 {
	local sample_label "Excl. AK HI DC and 2 AR counties"
}


**********************************************
*MAIN REGRESSION FILES
**********************************************
local P "pct_inc_lt3k pct_nonwhite " 
local D "pct_age_lt5yr pct_age_mt64yr pct_urban pct_rurf pct_inc_ge10k " 
local P64 "dem_share_p6460 dem_share_p64 dwin_p64 close_p64 dwin_close_p64"
local P60 " dwin_p60 close_p60 dwin_close_p60 "
local H "house_dem89 com_maj_lead89 com_maj_dem89 chair_lead89 chair_lead_dem89"
local C "dge_pc tax_pc62 pwe_pc62"
local R "riot6468"
local V "viet_death_sh_6070"
local A "scrp_op30 scrp_op59" 
local X "`D' `C' "



local X1 "`P' "
local X2 "pct_1kput pct_nonwhite"
local X3 "pct_2kput pct_nonwhite" 
local X4 "`A' " 
local X5 "`R'" 
local X6 "`V'"
local X7 "`P64'"
local X8 "`H'"
local X9 "`X1' `P64' `H' `A' `R' `V' "
local X10 "`X2' `P64' `H' `A' `R' `V' "
local X11 "`X3' `P64' `H' `A' `R' `V' "
local X0 "pct_inc_lt3k pct_1kput pct_2k pct_nonwhite `A' `R' `V' `P64' `H'"

sum pct_inc_lt3k pct_1kput pct_2k pct_nonwhite `A' plantation `R' `V' `P64' `H' fedc6568_pc _reg*
sum pct_inc_lt3k pct_1kput pct_2k pct_nonwhite `A' plantation `R' `V' `P64' `H' fedc6568_pc  if region==3

cd "$output"

local r "replace"

*Regressions with state f.e. and only one hypothesis at a time
local i 0
	while `i'<=11 {			

areg fedc6568_pc `X`i'' `X' , robust a(stfips)
	outreg2 `X`i'' using  "table2a_uw_r3.xls.xls", `r' `outopts' ///
					ctitle("Federal CAP Funds PC `y'")				/// EXCEL
					addtext("State FE", "Yes", 	///
						"Sample", `"`sample_label'"')				//"""

areg fedc6568_pc `X`i'' `X' if fedc6568_pc>0, robust a(stfips)
	outreg2 `X`i'' using  "table2b_uw_r3.xls.xls", `r' `outopts' ///
					ctitle("Federal CAP Funds PC `y'")				/// EXCEL
					addtext("State FE", "Yes", 	///
						"Sample", `"`sample_label'"')				//"""

areg anyfedc `X`i'' `X'  , robust a(stfips)
	outreg2 `X`i'' using  "table2c_uw_r3.xls.xls", `r' `outopts' ///
					ctitle("Federal CAP Funds PC `y'")				/// EXCEL
					addtext("State FE", "Yes", 	///
						"Sample", `"`sample_label'"')				//"""
local r "append"						
						
local i = `i'+1
}

local r "replace"
*South only
local i 0
	while `i'<=11 {			

areg fedc6568_pc `X`i'' `X' if region==3, robust a(stfips)
	outreg2 `X`i'' using  "table3a_uw_r3.xls.xls", `r' `outopts' ///
					ctitle("Federal CAP Funds PC `y'")				/// EXCEL
					addtext("State FE", "Yes", 	///
						"Sample", `"`sample_label'"')				//"""

areg fedc6568_pc `X`i'' `X' if fedc6568_pc>0 & region==3, robust a(stfips)
	outreg2 `X`i'' using  "table3b_uw_r3.xls.xls", `r' `outopts' ///
					ctitle("Federal CAP Funds PC `y'")				/// EXCEL
					addtext("State FE", "Yes", 	///
						"Sample", `"`sample_label'"')				//"""

areg anyfedc `X`i'' `X'  if region==3, robust a(stfips)
	outreg2 `X`i'' using  "table3c_uw_r3.xls.xls", `r' `outopts' ///
					ctitle("Federal CAP Funds PC `y'")				/// EXCEL
					addtext("State FE", "Yes", 	///
						"Sample", `"`sample_label'"')				//"""
local r "append"						
						
local i = `i'+1
}
log close
exit
