**************************************************
*
* Table B6: Effects on turnout and Republican vote
*
**************************************************

global program "TableB6"

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_County", 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"

// Generate variables

xtset county election
g lag_dem_pres_tev=l.dem_pres_tev
g lag_pop_pres_tev=l.pop_pres_tev
g lag_rep_pres_tev=l.rep_pres_tev

// The sample

qui reghdfe dempop_pres_ttl speech l.dem_pres_ttl l.pop_pres_ttl 	$demo if year==1896 & state_speech==1 & railroad_dum==1, cluster(district) a(state)
keep if e(sample)
drop if year!=1896

****************************
***** 2. TABLE RESULTS *****
****************************

// Speech (Binary) (Column 1)

preserve

g dep_var=speech

sureg (dempop_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(rep_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //	
suregr, cluster(district)
estimates store cs_binary_con

sureg (rep_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(ttl_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //
suregr, cluster(district)
estimates store cs_binary_ttl

qui sum dempop_pres_tev if e(sample)
scalar mean_d=r(mean)
estadd scalar mean_d
qui sum rep_pres_tev if e(sample)
scalar mean_r=r(mean)
estadd scalar mean_r
qui sum ttl_pres_tev if e(sample)
scalar mean_t=r(mean)
estadd scalar mean_t

restore

// Speeches/10k pop. (Column 2)

preserve

g dep_var=speeches_10k

sureg (dempop_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(rep_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) 
suregr, cluster(district)
estimates store cs_count_con

sureg (rep_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(ttl_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //
suregr, cluster(district)
estimates store cs_count_ttl
	
qui sum dempop_pres_tev if e(sample)
scalar mean_d=r(mean)
estadd scalar mean_d
qui sum rep_pres_tev if e(sample)
scalar mean_r=r(mean)
estadd scalar mean_r
qui sum ttl_pres_tev if e(sample)
scalar mean_t=r(mean)
estadd scalar mean_t

restore

// Speeches/10k pop. and squared (Column 3)

preserve

g dep_var=speeches_10k
g dep_var2=speeches_10k*speeches_10k

sureg (dempop_pres_tev dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(rep_pres_tev dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //	
suregr, cluster(district)
estimates store cs_countsq_con

sureg (rep_pres_tev dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(ttl_pres_tev dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //
suregr, cluster(district)
estimates store cs_countsq_ttl
	
qui sum dempop_pres_tev if e(sample)
scalar mean_d=r(mean)
estadd scalar mean_d
qui sum rep_pres_tev if e(sample)
scalar mean_r=r(mean)
estadd scalar mean_r
qui sum ttl_pres_tev if e(sample)
scalar mean_t=r(mean)
estadd scalar mean_t

restore

// Distance (log km) (Column 4)

preserve

g dep_var=ldist_speech_rail

sureg (dempop_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(rep_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //	
suregr, cluster(district)
estimates store cs_dist_con

sureg (rep_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev		$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) ///
	(ttl_pres_tev dep_var lag_dem_pres_tev lag_pop_pres_tev	lag_rep_pres_tev			$demo $geog $econ i.state if year==1896 & state_speech==1 & railroad_dum==1) //
suregr, cluster(district)
estimates store cs_dist_ttl
	
qui sum dempop_pres_tev if e(sample)
scalar mean_d=r(mean)
estadd scalar mean_d
qui sum rep_pres_tev if e(sample)
scalar mean_r=r(mean)
estadd scalar mean_r
qui sum ttl_pres_tev if e(sample)
scalar mean_t=r(mean)
estadd scalar mean_t

restore

***************************
***** 3. EXPORT TABLE *****
***************************

// Labels

la var dempop_pres_tev "\textit{Democratic vote (\% eligible) in 1896}" // [0.5em] \hline 
la var rep_pres_tev "\begin{comment} \textit{Republican vote (\% eligible) in 1896}"

// Table, Dem and Rep

estout cs_binary_con cs_count_con cs_countsq_con cs_dist_con /// 
	using "$tables/$program.tex", replace style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev) /// 
	order(dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev) /// 
	varlabels(dep_var "\hline \\ Speech variable" dep_var2 "[0.5em] Speech variable squared" lag_dem_pres_tev "[0.5em] Democratic vote (\% eligible) in 1892" lag_pop_pres_tev "[0.5em] Populist vote (\% eligible) in 1892" lag_rep_pres_tev "[0.5em] Republican vote (\% eligible) in 1892") /// 
	title(Effects on turnout and Republican vote) ///
	prehead("\begin{table}[t!]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{scriptsize}" ///
	"\caption{@title}\label{$program}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///
	"												&\multicolumn{1}{c}{(1)} 		&\multicolumn{1}{c}{(2)}  		&\multicolumn{1}{c}{(3)} 		&\multicolumn{1}{c}{(4)}\\" ///	
	"												&\multicolumn{1}{c}{Speech}  	&\multicolumn{1}{c}{Speeches/} 	&\multicolumn{1}{c}{Speeches/} 	&\multicolumn{1}{c}{Distance}\\" ///
	"\multicolumn{1}{l}{\textit{Dep. Variable}} 	&\multicolumn{1}{c}{(binary)}	&\multicolumn{1}{c}{10k pop} 	&\multicolumn{1}{c}{10k pop} 	&\multicolumn{1}{c}{(log km)}\\" ///
	"\hline") ///
	postfoot("\end{comment}" ///
	"") ///

// Table, Rep and Turnout

la var rep_pres_tev "\\ \hline \textit{Republican vote (\% eligible) in 1896}"
la var ttl_pres_tev "[1em] \hline \textit{Turnout (\% eligible) in 1896}"

estout cs_binary_ttl cs_count_ttl cs_countsq_ttl cs_dist_ttl /// 
	using "$tables/$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_d mean_r mean_t N, lab("Mean Democratic vote" "Mean Republican vote" "Mean turnout" "Observations") fmt(2 2 2 %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev) /// 
	order(dep_var dep_var2 lag_dem_pres_tev lag_pop_pres_tev lag_rep_pres_tev) /// 
	varlabels(dep_var "\hline \\ Speech variable" dep_var2 "[0.5em] Speech variable squared" lag_dem_pres_tev "[0.5em] Democratic vote (\% eligible) in 1892" lag_pop_pres_tev "[0.5em] Populist vote (\% eligible) in 1892" lag_rep_pres_tev "[0.5em] Republican vote (\% eligible) in 1892") /// 
	title(Effects on turnout and Republican vote) ///
	indicate("\\ Demographic controls = urban_dum" ///	
	"Geographic controls = railroad_dens" ///	
	"Economic controls = perc_farm" ///	
	"State FE = *.state" ///	
	, labels(Yes )) ///
	prefoot("\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}: Seemingly unrelated regressions (SUR). The unit of observation is a county. " ///
	"All regressions include the full set of controls presented in Table \ref{Table1}. " ///
	"All regressions include state fixed-effects. " ///
	"Standard errors clustered at the congressional district level in parentheses." /// 
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///	
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable} " ///
	"\end{center}" ///
	"\end{table}") //	

cap log close
