*************************************************************************
*
* Table B3: Details on estimating methods: Cross-sectional falsifications
*
*************************************************************************
 
global program "TableB3"

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"

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

// Baseline for 1884-1892

xtset county election
g lag2_dem_pres_ttl=l2.dem_pres_ttl
g lag2_pop_pres_ttl=l2.pop_pres_ttl

forvalues y=1884(4)1892{
	
	sum year if year==`y' 
	
	reghdfe dempop_pres_ttl speech lag_dem_pres_ttl 						$demo $geog $econ if year==`y' & state_speech==1 & railroad_dum==1, cluster(district) a(state) 
	estimates store false_binary_`y'

}

// Baseline for 1896

reghdfe dempop_pres_ttl speech lag_dem_pres_ttl lag_pop_pres_ttl			$demo $geog $econ if year==1896 & state_speech==1 & railroad_dum==1, cluster(district) a(state)  
estimates store false_binary_1896

// Baseline for 1900 controlling for 1892

reghdfe dempop_pres_ttl speech lag2_dem_pres_ttl lag2_pop_pres_ttl			$demo $geog $econ if year==1900 & state_speech==1 & railroad_dum==1, cluster(district) a(state)  
estimates store false_binary_1900

// Within-district for 1884-1892

forvalues y=1884(4)1892{
	
	sum year if year==`y' 
	
	reghdfe dempop_pres_ttl speech lag_dem_pres_ttl 							$demo $geog $econ if year==`y' & state_speech==1 & railroad_dum==1, cluster(district) a(district)
	estimates store district_binary_`y'

}

// Within-district for 1896

reghdfe dempop_pres_ttl speech lag_dem_pres_ttl lag_pop_pres_ttl			$demo $geog $econ if year==1896 & state_speech==1 & railroad_dum==1, cluster(district) a(district)
estimates store district_binary_1896

// Within-district for 1900 controlling for 1892

reghdfe dempop_pres_ttl speech lag2_dem_pres_ttl lag2_pop_pres_ttl			$demo $geog $econ if year==1900 & state_speech==1 & railroad_dum==1, cluster(district) a(district)
estimates store district_binary_1900

// Nearest-neighbor matching for 1884-1892

forvalues y=1884(4)1892{
	
	teffects nnmatch (dempop_pres_ttl lag_dem_pres_ttl $demo $geog $econ i.state) (speech) if year==`y' & state_speech==1 & railroad_dum==1, ///
		metric(euclidean) biasadj(lag_dem_pres_ttl $demo_cont $geog $econ_cont) vce(robust) nneighbor(1)
	estimates store nnd_binary_`y'
	
}

// Nearest-neighbor matching for 1896

teffects nnmatch (dempop_pres_ttl lag_dem_pres_ttl lag_pop_pres_ttl $demo $geog $econ i.state) (speech) if year==1896 & state_speech==1 & railroad_dum==1, ///
	metric(euclidean) biasadj(lag_dem_pres_ttl lag_pop_pres_ttl $demo_cont $geog $econ_cont) vce(robust) nneighbor(1)
estimates store nnd_binary_1896

// Nearest-neighbor matching for 1900 controlling for 1892

teffects nnmatch (dempop_pres_ttl lag2_dem_pres_ttl lag2_pop_pres_ttl $demo $geog $econ i.state) (speech) if year==1900 & state_speech==1 & railroad_dum==1, ///
	metric(euclidean) biasadj(lag2_dem_pres_ttl lag2_pop_pres_ttl $demo_cont $geog $econ_cont) vce(robust) nneighbor(1)
estimates store nnd_binary_1900

// Neighbor pairs for 1884, 1888, 1892

use "$data/Data_Neighbor_Pairs", clear

xtset county_nbr election
g lag2_dem_pres_ttl=l2.dem_pres_ttl
g lag2_pop_pres_ttl=l2.pop_pres_ttl

forvalues y=1884(4)1892{
	
	sum year if year==`y'
	
	reghdfe dempop_pres_ttl speech lag_dem_pres_ttl lag_pop_pres_ttl	$demo $geog $econ if year==`y' & sample_speech==1 & railroad_dum==1, cluster(nbr_fe) a(nbr_fe)  
	estimates store np_binary_`y'

}

// Neighbor pairs for 1896

reghdfe dempop_pres_ttl speech lag_dem_pres_ttl lag_pop_pres_ttl	$demo $geog $econ if year==1896 & sample_speech==1 & railroad_dum==1, cluster(nbr_fe) a(nbr_fe)  
estimates store np_binary_1896

// Neighbor pairs for 1900 controlling for 1892

reghdfe dempop_pres_ttl speech lag2_dem_pres_ttl lag2_pop_pres_ttl	$demo $geog $econ if year==1900 & sample_speech==1 & railroad_dum==1, cluster(nbr_fe) a(nbr_fe)  
estimates store np_binary_1900

// Entropy balancing for 1884, 1888, 1892

use "$data/Data_County", clear

xtset county election
g lag2_dem_pres_ttl=l2.dem_pres_ttl
g lag2_pop_pres_ttl=l2.pop_pres_ttl

forvalues y=1884(4)1892{
	
	sum year if year==`y' 
	
	reghdfe dempop_pres_ttl speech lag_dem_pres_ttl 							$demo $geog $econ [w=w_full`y'] if year==`y' & state_speech==1 & railroad_dum==1, cluster(district) a(state)  
	estimates store entropy_binary_`y'

}

// Entropy balancing for 1896

reghdfe dempop_pres_ttl speech lag_dem_pres_ttl lag_pop_pres_ttl			$demo $geog $econ [w=w_full1896] if year==1896 & state_speech==1 & railroad_dum==1, cluster(district) a(state)  
estimates store entropy_binary_1896

// Entropy balancing for 1900

reghdfe dempop_pres_ttl speech lag2_dem_pres_ttl lag2_pop_pres_ttl			$demo $geog $econ [w=w_full1900] if year==1900 & state_speech==1 & railroad_dum==1, cluster(district) a(state)  
estimates store entropy_binary_1900

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

// Fixed effects

estfe . false*, labels(state "State FE")
return list

estfe . entropy*, labels(state "State FE")
return list

estfe . district*, labels(district "Congressional district FE")
return list

estfe . np*, labels(nbr_fe "Neighbor-Pair FE")
return list

// Panel A

esttab false_binary_* ///
	using "$tables/$program.tex", replace fragment style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N N_clust r2_a, lab("Observations" "Clusters" "Adjusted $ R^2 $") fmt(%9.0fc %9.0fc 2)) ///
	collabels(none) nonumbers ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(speech) /// 
	order(speech) /// 
	varlabels(speech "Speech (binary)") /// 
	title(Details on estimating methods: Cross-sectional falsifications) ///
	indicate("\\ State FE = 0.state" ///
	, labels(Yes )) ///
	prehead("\begin{table}[h!]" ///
	"\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}{(5)} \\" ///	  
	"\multicolumn{1}{l}{\textit{Dep. Variable}} &\multicolumn{5}{c}{Democratic vote (\%) in 1896} \\" /// 
	"\cmidrule(lr){2-6}   " ///
	"\multicolumn{1}{l}{\textit{Election year}}		&\multicolumn{1}{c}{1884}		&\multicolumn{1}{c}{1888} 		&\multicolumn{1}{c}{1892} 		&\multicolumn{1}{c}{1896}		&\multicolumn{1}{c}{1900} \\" ///
	"\multicolumn{1}{l}{}							&\multicolumn{1}{c}{(None)}		&\multicolumn{1}{c}{(None)}		&\multicolumn{1}{c}{(None)}		&\multicolumn{1}{c}{(Bryan)}	&\multicolumn{1}{c}{(D and R)} \\" ///
	"\hline") ///
	posthead("\multicolumn{6}{c}{Panel A. Baseline (within state) estimation} \\" ///
	"\hline" ///
	"\\") ///
	prefoot("\hline") //

// Panel B

esttab np_binary_* /// 
	using "$tables/$program.tex", append fragment style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N N_clust r2_a, lab("Observations" "Clusters" "Adjusted $ R^2 $") fmt(%9.0fc %9.0fc 2)) ///
	collabels(none) nonumbers ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(speech) /// 
	order(speech) /// 
	varlabels(speech "Speech (binary)") /// 
	indicate("\\ Neighbor-pair FE = 0.nbr_fe" ///
	, labels(Yes )) ///
	prehead("\hline") ///
	posthead("\multicolumn{6}{c}{Panel B. Within neighbor-pair estimation} \\" ///
	"\hline" ///
	"\\") ///
	prefoot("\hline") //

// Panel C

esttab district_binary_* ///
	using "$tables/$program.tex", append fragment style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N N_clust r2_a, lab("Observations" "Clusters" "Adjusted $ R^2 $") fmt(%9.0fc %9.0fc 2)) ///
	collabels(none) nonumbers ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(speech) /// 
	order(speech) /// 
	varlabels(speech "Speech (binary)") /// 
	indicate("\\ Congressional district FE = 0.district" ///
	, labels(Yes )) ///
	prehead("\hline") ///
	posthead("\multicolumn{6}{c}{Panel C. Within district estimation} \\" ///
	"\hline" ///
	"\\") ///
	prefoot("\hline") //

// Panel D

esttab entropy_binary_* ///
	using "$tables/$program.tex", append fragment style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N N_clust r2_a, lab("Observations" "Clusters" "Adjusted $ R^2 $") fmt(%9.0fc %9.0fc 2)) ///
	collabels(none) nonumbers ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(speech) /// 
	order(speech) /// 
	varlabels(speech "Speech (binary)") /// 
	indicate("\\ State FE = 0.state" ///
	, labels(Yes )) ///
	prehead("\hline") ///
	posthead("\multicolumn{6}{c}{Panel D. Entropy balancing estimation} \\" ///
	"\hline" ///
	"\\") ///
	prefoot("\hline") //
	
// Panel E
	
esttab nnd_binary_* ///
	using "$tables/$program.tex", append fragment style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	coeflabels(r1vs0.speech   "Speech (binary)") ///
	stats(N, lab("Observations") fmt(%9.0fc)) ///
	collabels(none) nonumbers ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(*) /// 
	order(*) /// 	
	prehead("\hline") ///
	posthead("\multicolumn{6}{c}{Panel E. Nearest neighbor matching estimation} \\" ///
	"\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}: OLS regressions. The unit of observation is a county. " /// 
	"All regressions include the full set of controls presented in Table \ref{Table1} with the exception of the Matching estimator. " ///
	"Counties matched using the set of controls presented in Table \ref{Table1} in Panel E. " ///
	"Panels A, C, and D: standard errors clustered at the congressional district level in parentheses; " ///
	"Panel B: at the neighbor-pair level. " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///		"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable} " ///
	"\end{center}" ///
	"\end{table}") //	

cap log close
