global program "EEREV-D-21-00004_TableC3"

cap log close
cap log using "$log\log_$program$today", replace

**** REPLICATION OF TABLE C3 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. REGRESSIONS
	2. TABLE FOR PAPER
*/

**************************
***** 1. REGRESSIONS *****
**************************

// Import Cantonal data

use $data\EEREV-D-21-00004_Data_Municipalities.dta, clear

// Macros

global geogr_endow 			"water lelevation_mean lelevation_std ldist_de" 
global pop 					"perc_b_1928_1945 perc_b_1946_1964 perc_b_1965_1980 perc_b_1981_1996 perc_male_counter"
global demog_chara 			"lpop_counter perc_fore $pop"
global socec_aspec 			"perc_bacplus perc_bluecollar perc_chom lrev_median lrev_sd"

// Control vectors

global sigma 				"perc_prot_church pop_jew p_french_name lpop_1936 perc_fore_1936 perc_dial_1936 perc_disp_1946 $geogr_endow perc_droi_1936_ins"
global w 					"$demog_chara $socec_aspec"
global dialect 				"dialect_lux dialect_mos dialect_rhe dialect_pal dialect_als dialect_hau dialect_lor dialect_fra"

// Controls vector

global rdd2 				"rdd_lat rdd_lon rdd_lat_2 rdd_lon_2 rdd_lat_lon"

// Get weights

keep if sample==1

ebalance alsace perc_prot_church if annee==1965 & sample==1, targets(3) generate(w) keep(w) replace
bysort com: egen w_sigma=max(w)
cap drop w

// First stage

foreach year in 1965 1969 1974 1995 2002 2007 2012 2017{

	ivreghdfe perc_i_full perc_e_1908_1927 ///
		perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 perc_disp_1946 /// 
		$sigma $w $rdd2 /// 
		if annee==`year' & sample==1 [pweight=w_sigma], cluster(ct_1936_enc) ///
		a(borderfe $dialect pop_jew water) partial($sigma $w)
		
	estimates store P`year'T1_FS
	sum perc_i_full  if annee==`year' & sample==1 //
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}

// 1965-1969 FOR TABLE

foreach year in 1969{

	reg perc_voixexd_ins perc_b_1903_1912 if annee==`year' & sample==1, cluster(ct_1936_enc)
	estimates store P`year'T1_VOTE, title(`year'R1)
	qui sum perc_voixexd_ins if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}

// Radical-Right

foreach year in 1965 1974 1995 2002 2007 2012 2017{
	
	ivreghdfe perc_voixexd_ins (perc_i_full = perc_e_1908_1927) ///
		perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 perc_disp_1946 /// 
		$sigma $w $rdd2 /// 
		if annee==`year' & sample==1 [pweight=w_sigma], cluster(ct_1936_enc) ///
		a(borderfe $dialect) partial($sigma $w)

	estimates store P`year'T1_VOTE
	scalar f = e(rkf)
	estadd scalar F_fs=f
	qui sum perc_voixexd_ins if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
	
}

// Abstention

foreach year in 1965 1969 1974 1995 2002 2007 2012 2017{
	
	tab annee if annee==`year'
	
	ivreghdfe perc_bna_ins (perc_i_full = perc_e_1908_1927) ///
		perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 perc_disp_1946 /// 
		$sigma $w $rdd2 /// 
		if annee==`year' & sample==1 [pweight=w_sigma], cluster(ct_1936_enc) ///
		a(borderfe $dialect) partial($sigma $w)

	estimates store P`year'T1_ABST
	scalar f = e(rkf)
	estadd scalar F_fs=f
	qui sum perc_bna_ins if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}

estfe . P*, labels(dialect_lux "Historical dialects")
return list

******************************
***** 2. TABLE FOR PAPER *****
******************************

// Labels

la var perc_e_1908_1927 	"\\ Eligible births (\%)"
la var perc_i_full 			"\\ Conscripted (\%)"

// First-Stage

estout P1965T1_FS P1969T1_FS P1974T1_FS P1995T1_FS P2002T1_FS P2007T1_FS P2012T1_FS P2017T1_FS ///
	using "$results\\$program.tex", replace style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y, lab("\\ Mean dep. variable") fmt(2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(perc_e_1908_1927) ///
	order(perc_e_1908_1927) ///
	title("Conscription and electoral outcomes: Balancing religious affiliations") ///
	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}{(5)}  &\multicolumn{1}{c}{(6)}  &\multicolumn{1}{c}{(7)} &\multicolumn{1}{c}{(8)}\\" ///   
	"	&\multicolumn{3}{c}{Earlier elections} &\multicolumn{5}{c}{Later elections}\\" ///
	"\cmidrule(lr){2-4} \cmidrule(lr){5-9}" ///
	"\multicolumn{1}{l}{\textit{Election year}}&\multicolumn{1}{c}{1965} &\multicolumn{1}{c}{1969} &\multicolumn{1}{c}{1974} &\multicolumn{1}{c}{1995}  &\multicolumn{1}{c}{2002} &\multicolumn{1}{c}{2007} &\multicolumn{1}{c}{2012} &\multicolumn{1}{c}{2017}\\" ///
	"%\hline" ///
	"\cmidrule(lr){2-9}" ///
	"& \multicolumn{8}{c}{Panel A: First-Stage Estimates. Dep. Variable: Conscripted (\%)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

// Radical-Right

estout P1965T1_VOTE P1969T1_VOTE P1974T1_VOTE P1995T1_VOTE P2002T1_VOTE P2007T1_VOTE P2012T1_VOTE P2017T1_VOTE ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y, lab("\\ Mean dep. variable") fmt(2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(perc_i_full) ///
	order(perc_i_full) ///
	prehead("%\hline" ///
	"\cmidrule(lr){2-9}" ///
	"& \multicolumn{8}{c}{Panel B: 2SLS Estimates. Dep. Variable: Radical right-wing vote (\% of registered)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

// Abstention

estout P1965T1_ABST P1969T1_ABST P1974T1_ABST P1995T1_ABST P2002T1_ABST P2007T1_ABST P2012T1_ABST P2017T1_ABST ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y, lab("\\ Mean dep. variable") fmt(2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(perc_i_full) ///
	order(perc_i_full) ///
	prehead("%\hline" ///
	"\cmidrule(lr){2-9}" ///
	"& \multicolumn{8}{c}{Panel C: 2SLS Estimates. Dep. Variable: Abstention (\% of registered)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("")

// Closure

estout P1965T1_ABST P1969T1_ABST P1974T1_ABST P1995T1_ABST P2002T1_ABST P2007T1_ABST P2012T1_ABST P2017T1_ABST ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(F_fs N N_clust, lab("First-stage $ F $-statistic" "Observations" "Clusters") fmt(2 0 0)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	drop(*) ///	
	indicate( /// 	
	"Border segment FE = 0.borderfe25" ///
	"Historical dialect FE = 0.dialect_lux" ///
	"Full set of controls = perc_b_1903_1912" ///
	, labels(Yes )) ///
	prehead("\\ Lat-lon polynomial & 2nd & 2nd & 2nd & 2nd & 2nd & 2nd & 2nd & 2nd \\ ") ///
	posthead("") ///
	prefoot("\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"2SLS estimates of the effect of conscription into the Wehrmacht on support for radical right-wing candidates and on abstention when balancing religious affiliation. " ///
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at the canton level in parentheses. " ///
	"Panel A: First-stage estimates; " ///
	"Panels B and C: 2SLS estimates with radical right-wing vote and abstention as the outcome, respectively. " ///
	"Each column presents the estimation for a different election. " ///
	"All specifications include a quadratic polynomial in latitude and longitude ($ x+y+x^2+y^2+xy $). " ///
	"First-stage F-statistic is the Kleibergen-Paap rk Wald F-statistic of the first-stage estimation. " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///	
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close

capture erase $results\w.dta