**************************************
*
* Figure C4: Populist vote in Congress
*
**************************************
 
global program "FigureC4"

cap log close
cap log using "$log_files/log_$program$today", replace

clear all
set mem 2g
set more off
set matsize 11000
set scheme s1color

***************************
***** 1. PREPARE DATA *****
***************************

// Get data

use "$data/Data_Congress", clear

// Controls definition

global geog 		"railroad_dens ldist_capital ldist_largest county_lat county_lon" 
global demo 		"urban_dum perc_pop_dstr lpop_total perc_white perc_male21 perc_below21 perc_native perc_literate newsp_circ_elig" 
global demo_cont	"perc_pop_dstr lpop_total perc_white perc_male21 perc_below21 perc_native perc_literate newsp_circ_elig" 
global econ 		"perc_farm perc_manuf dlog_avbasket ldist_silver ldist_gold" 
global econ_cont	"perc_farm perc_manuf dlog_avbasket ldist_silver ldist_gold" 
global econ_p 		"perc_farm perc_manuf log_avbasket ldist_silver ldist_gold" 
global vote 		"lag_margin_pres_ttl" 			
global demo_add		"urban_dum lpop_total larea perc_white perc_below21 perc_native perc_literate newsp_circ_elig pop_male2144 pop_male4564 pop_male6599 perc_catholic perc_black"

// The sample

drop if year==1888

xtset county election

reghdfe dempop_pres_ttl speech l2.dem_pres_ttl l2.pop_pres_ttl	$demo $geog $econ if year==1896 & state_speech==1 & railroad_dum==1, cluster(district) a(state) // keepsing
g s=1*(e(sample))
bysort county: egen sample=max(s)
drop s

// Interactions

egen year_state=group(year state)

// Control vectors

global X "c.perc_farm#i.year c.perc_manuf#i.year"

// Figure for paper

cap g x=1
forvalues y=1890(2)1896{
	g speech_`y'=speech*(year==`y')
	la var speech_`y' "`y'" 
}

la var x "1892"

*****************************
***** 2. FIGURE RESULTS *****
*****************************

// Populist 1890-1894

reghdfe pop_cong_ttl speech_1890 x speech_1894 $X	railroad_dum $geog $demo $econ_p if sample==1 & state_speech==1 & year>=1890 & year<=1894, cluster(county) a(county year_state)
estimates store DD_pop_perc
qui sum pop_cong_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y
test speech_1890 speech_1894
return list
estadd scalar F_joint=r(F)
estadd scalar p_F_joint=r(p)

// Populist 1892-1894

reghdfe pop_cong_ttl x speech_1894 $X	railroad_dum $geog $demo $econ_p if sample==1 & state_speech==1 & year>=1892 & year<=1894, cluster(county) a(county year_state)
estimates store DD_pop_perc94
qui sum pop_cong_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Dem/Pop 1890-1894

reghdfe dempop_cong_ttl speech_1890 x speech_1894 $X	railroad_dum $geog $demo $econ_p if sample==1 & state_speech==1 & year>=1890 & year<=1894, cluster(county) a(county year_state)
estimates store DD_dempop_perc
qui sum dempop_cong_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y
test speech_1890 speech_1894
return list
estadd scalar F_joint=r(F)
estadd scalar p_F_joint=r(p)

// Dem/Pop 1890-1896

reghdfe dempop_cong_ttl speech_1890 x speech_1894 speech_1896 $X	railroad_dum $geog $demo $econ_p if sample==1 & state_speech==1 & year>=1890 & year<=1896, cluster(county) a(county year_state) // keepsing
estimates store DD_dempop_perc96
qui sum dempop_cong_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y
test speech_1890 speech_1894
return list
estadd scalar F_joint=r(F)
estadd scalar p_F_joint=r(p)

****************************
***** 3. EXPORT FIGURE *****
****************************

coefplot ////
	(DD_pop_perc,  mcolor(navy) msymbol(S) offset(-.3)) ///
	(DD_pop_perc94, mcolor(green) msymbol(D) offset(-.1)) ///
	(DD_dempop_perc, mcolor(orange) msymbol(T) offset(.1)) ///
	(DD_dempop_perc96, mcolor(maroon) msymbol(O) offset(.3)), ///
	base omitted mlabel mlabsize(vsmall) format(%9.2f) mlabposition(6) mlabcolor(navy) mlabgap(*2) /// 
	keep(speech_1890 x speech_1894 speech_1896) vertical levels(95) ciopts(recast(rcap) lc(gs13)) graphregion(color(white)) msymbol(S) mfcolor(white) pstyle(p3) /// 
	ytitle("Coefficient (95% C.I.)") ylabel(, angle(0) format(%9.0f)) /// 
	xline(3.5, lcolor(gs12) lpattern(dash)) xline(4.5, lcolor(gs12) lpattern(dash)) ///
	xlabel(1 `" "1890" "(None)" "' 2 `" "1892" "(None)" "' 3 `" "1894" "(None)" "' 4 `" "1896" "(Bryan)" "') /// 
	xscale(r(0 5)) legend(lab(2 "Populist 1890-1894") lab(4 "Populist 1892-1894") lab(6 "Dem/Pop 1890-1894") lab(8 "Dem/Pop 1890-1896") c(4) order(2 4 6 8) symx(*0.25) region(col(white)) size(small)) ///  
	yline(0, lpattern(dash)) yline(1, lpattern(dash) lcolor(gs15)) yline(2, lpattern(dash) lcolor(gs15)) yline(3, lpattern(dash) lcolor(gs15)) yline(-1, lpattern(dash) lcolor(gs15)) yline(-2, lpattern(dash) lcolor(gs15)) //
graph export "$figures/$program.pdf", replace

cap log close
