**************************************
*
* Table D4: Rival campaign information
*
**************************************

global program "TableD4"

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"
  
// The sample

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) // keepsing
g sample=1*(e(sample))

keep if sample==1

// Generate variables

gen ratio_nwsp_7_election_1986 = (1+ nwsp_McKinley_7_election_1896)/(1+ nwsp_Bryan_7_election_1896)

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

// Full sample (Column 1)

reghdfe dempop_pres_ttl speech lag_dem_pres_ttl lag_pop_pres_ttl $demo $geog $econ if sample==1, cluster(district) a(state) 
estimates store McK_baseline
qui sum dempop_pres_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Full sample (Column 2)

reghdfe dempop_pres_ttl speech nwsp_McKinley_7_elect_1896_elig nwsp_Bryan_7_elect_1896_elig  /// 
	lag_dem_pres_ttl lag_pop_pres_ttl $demo $geog $econ if sample==1, cluster(district) a(state) 
estimates store McK_count
qui sum dempop_pres_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Full sample (Column 3)

reghdfe dempop_pres_ttl speech   ratio_nwsp_7_election_1986 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 McK_ratio
qui sum dempop_pres_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Full sample (Column 4)

reghdfe dempop_pres_ttl  c.speech##c.ratio_nwsp_7_election_1986 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 McK_ratio_interact
qui sum dempop_pres_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// At least 1 mention (Column 5)

reghdfe dempop_pres_ttl  c.speech##c.ratio_nwsp_7_election_1986 ///
	lag_dem_pres_ttl lag_pop_pres_ttl $demo $geog $econ if  (nwsp_McKinley_7_election_1896>0 | nwsp_Bryan_7_election_1896>0) & year==1896 & state_speech==1 & railroad_dum==1, cluster(district) a(state) 
estimates store McK_ratio_interact_nozero
qui sum dempop_pres_ttl if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

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

// Fixed effects

estfe . McK_baseline McK_count McK_ratio McK_ratio_interact McK_ratio_interact_nozero, labels(state "State FE")
return list

// Labels

la var nwsp_McKinley_7_elect_1896_elig 	"[0.5em] McKinley newspaper mentions (per elig. voter)"
la var nwsp_Bryan_7_elect_1896_elig 	"[0.5em] Bryan newspaper mentions (per elig. voter)"
la var ratio_nwsp_7_election_1986 		"[0.5em] McKinley to Bryan news mentions (ratio)"

// Table

estout McK_baseline McK_count McK_ratio McK_ratio_interact McK_ratio_interact_nozero ///
	using "$tables/$program.tex", replace style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y N N_clust r2_a, lab("Mean dep. variable" "Observations" "Clusters" "Adjusted $ R^2 $") fmt(2 %9.0fc 0 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(speech   nwsp_McKinley_7_elect_1896_elig nwsp_McKinley_7_elect_1896_elig nwsp_Bryan_7_elect_1896_elig  ratio_nwsp_7_election_1986 c.speech#c.*) /// 
	order(speech  nwsp_McKinley_7_elect_1896_elig nwsp_McKinley_7_elect_1896_elig nwsp_Bryan_7_elect_1896_elig  ratio_nwsp_7_election_1986 c.speech#c.*) ///
	varlabels(speech "Speech (binary)" c.speech#c.ratio_nwsp_7_election_1986 "[0.5em] Speech $ \times $ McKinley to Bryan news mentions") /// 
	title(Rival campaign information) ///
	indicate("\\  Demographic controls = urban_dum" ///	
	"Geographic controls = railroad_dens" ///	
	"Economic controls = perc_farm" ///
	"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}\\" ///
	"\hline" /// 
	"\multicolumn{1}{l}{\textit{Sample}} &\multicolumn{1}{c}{Full} &\multicolumn{1}{c}{Full} &\multicolumn{1}{c}{Full} &\multicolumn{1}{c}{Full} &\multicolumn{1}{c}{At least 1}  \\" /// 
	"\multicolumn{1}{l}{}   &\multicolumn{1}{c}{sample} &\multicolumn{1}{c}{sample} &\multicolumn{1}{c}{sample} &\multicolumn{1}{c}{sample} &\multicolumn{1}{c}{mention}\\" ///
	"\hline") ///
	posthead("\\") ///
	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. " ///
	"Demographic controls: Urban (binary), District population (\%),  Log population, White (\%), Male above 21 (\%), Native (\%). " ///
	"Geographic controls: Railroad density (km per sq. km), Distance to state capital (log), Distance to state largest city (log), Latitude, Longitude. " ///
	"Economic controls: Farmers (\%), Manufacture workers (\%)." ///
	"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
