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

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

**** REPLICATION OF TABLE 6 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. PREPARE DATA
	2. REGRESSIONS
	3. TABLE FOR PAPER
*/

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

// Import Municipality data

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

// Reshape

drop if sample==0
drop sample

reshape long voix_, i(com dep annee) j(candidate) string
drop if voix_==.
rename voix_ voix

// Merge with Candidate data

merge m:1 annee candidate using $data\EEREV-D-21-00004_Data_Candidates
tab candidate annee if _merge==1
rename _merge sample

// Generate vote shares

g perc_exp=(voix*100)/exprimes 
g perc_ins=(voix*100)/inscrits
format perc_* %9.2f

// Keep sample

keep if sample==3

// Macros

global rdd2_cand 			"i.cand_year#c.rdd_lat i.cand_year#c.rdd_lon i.cand_year#c.rdd_lat_2 i.cand_year#c.rdd_lon_2 i.cand_year#c.rdd_lat_lon"

global geogr_endow_std 		"c.water#c.neg_std c.lelevation_mean#c.neg_std c.lelevation_std#c.neg_std c.ldist_de#c.neg_std"
global pop_std 				"c.perc_b_1928_1945#c.neg_std c.perc_b_1946_1964#c.neg_std c.perc_b_1965_1980#c.neg_std c.perc_b_1981_1996#c.neg_std c.perc_male_counter#c.neg_std"
global demog_chara_std 		"c.lpop_counter#c.neg_std c.perc_fore#c.neg_std $pop_std"
global socec_aspec_std 		"c.perc_bacplus#c.neg_std c.perc_bluecollar#c.neg_std c.perc_chom#c.neg_std c.lrev_median#c.neg_std c.lrev_sd#c.neg_std"
global sigma_std 			"c.perc_prot_church#c.neg_std c.pop_jew#c.neg_std c.p_french_name#c.neg_std c.lpop_1936#c.neg_std c.perc_fore_1936#c.neg_std c.perc_dial_1936#c.neg_std c.perc_disp_1946#c.neg_std $geogr_endow_std c.perc_droi_1936_ins#c.neg_std"
global w_std 				"$demog_chara_std $socec_aspec_std"

**************************
***** 2. REGRESSIONS *****
**************************

// Reduced-form

foreach var in neg{

	foreach year in 1965 1969 1974 1995 2002 2007 2012 2017{
			
		sum annee if annee==`year'
		
		ivreghdfe perc_ins perc_e_1908_1927 c.perc_e_1908_1927#c.`var'_std ///
			perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 /// 
			c.perc_b_1903_1912#c.`var'_std c.perc_b_1913_1922#c.`var'_std c.perc_b_1923_1932#c.`var'_std /// 
			$sigma_std $w_std $rdd2_cand /// 
			if annee==`year' & sample==3, cluster(com) ///
			a(i.cand_year#i.borderfe i.dialect#i.cand_year) partial($sigma_std $w_std $rdd2_cand) // 
		estimates store P`year'T1_`var'_RF
		qui sum perc_ins if e(sample)
		scalar mean_y=r(mean)
		scalar sd_y=r(sd)
		estadd scalar mean_y
	
		sum `var'_std if e(sample) [w=poll], d
		estadd scalar max=r(max)
		estadd scalar p50=r(p50)
		
	}
}

// Two-stage least-squares

foreach var in neg{ 

	foreach year in 1965 1969 1974 1995 2002 2007 2012 2017{
			
		sum annee if annee==`year'
		
		ivreghdfe perc_ins ///
			(perc_i_full c.perc_i_full#c.`var'_std = perc_e_1908_1927 c.perc_e_1908_1927#c.`var'_std) ///
			perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 /// 
			c.perc_b_1903_1912#c.`var'_std c.perc_b_1913_1922#c.`var'_std c.perc_b_1923_1932#c.`var'_std /// 
			$sigma_std $w_std $rdd2_cand ///
			if annee==`year' & sample==3, cluster(com) ///
			a(i.cand_year#i.borderfe i.dialect#i.cand_year) partial($sigma_std $w_std $rdd2_cand) //
		estimates store P`year'T1_`var'_R
		scalar f = e(rkf)
		estadd scalar F_fs=f
		scalar f_under=e(idstat)
		estadd scalar F_u=f_under
		qui sum perc_ins if e(sample)
		scalar mean_y=r(mean)
		scalar sd_y=r(sd)
		estadd scalar mean_y
	
		sum `var'_std if e(sample) [w=poll], d
		estadd scalar max=r(max)
		estadd scalar p50=r(p50)
		
	}
}

******************************
***** 3. TABLE FOR PAPER *****
******************************

// Fixed effects

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

// Reduced form

estout P1965T1_neg_RF P1969T1_neg_RF P1974T1_neg_RF P1995T1_neg_RF P2002T1_neg_RF P2007T1_neg_RF P2012T1_neg_RF P2017T1_neg_RF ///
	using "$results\\$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(perc_e_1908_1927 c.perc_e_1908_1927#c.neg_std) ///
	varlabels(perc_e_1908_1927 "\\ Eligible births (\%)" c.perc_e_1908_1927#c.neg_std "[0.3em] Eligible births (\%) $ \times $ Radicalism [std]") ////
	title(Radical and moderate candidates: Reduced-form and second-stage estimates) ///
	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{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}\\" ///
	"\cmidrule(lr){2-9}" ///
	"& \multicolumn{8}{c}{Panel A: Reduced-Form Estimates. Dep. Variable: Candidate vote (\% of registered)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

// 2SLS

estout P1965T1_neg_R P1969T1_neg_R P1974T1_neg_R P1995T1_neg_R P2002T1_neg_R P2007T1_neg_R P2012T1_neg_R P2017T1_neg_R ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(F_fs F_u, lab("\\ First-stage $ F $-statistic" "Underidentification $ F $-statistic") fmt(2 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(perc_i_full c.perc_i_full#c.neg_std) ///
	varlabels(perc_i_full "\\ Conscription proxy (\%)" c.perc_i_full#c.neg_std "[0.3em] Conscription (\%) $ \times $ Radicalism [std]") ////
	prehead("\cmidrule(lr){2-9}" ///
	"& \multicolumn{8}{c}{Panel B: 2SLS Estimates. Dep. Variable: Candidate vote (\% of registered)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

// Closure

estout P1965T1_neg_R P1969T1_neg_R P1974T1_neg_R P1995T1_neg_R P2002T1_neg_R P2007T1_neg_R P2012T1_neg_R P2017T1_neg_R ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y N N_clust , lab("Mean dependent variable" "Observations" "Clusters") fmt(2 %9.0fc %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	drop(*) ///	
	indicate( /// 	
	"Candidate-border segment FE = 0.cand_year#0.borderfe25" ///
	"Candidate-dialect FE = 0.dialect#0.cand_year" ///
	"Full set of controls $ \times $ Radicalism [std] = perc_b_1903_1912" ///	
	, labels(Yes )) ///
	prehead("Candidate-lat-lon polynomial & 2nd & 2nd & 2nd & 2nd & 2nd & 2nd & 2nd & 2nd \\ ") ///
	posthead("") ///
	prefoot("\hline") ///
	postfoot("")

// Radicalism distribution
	
estout P1965T1_neg_R P1969T1_neg_R P1974T1_neg_R P1995T1_neg_R P2002T1_neg_R P2007T1_neg_R P2012T1_neg_R P2017T1_neg_R ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(p50 max, lab("\multicolumn{1}{l}{Median candidate (std.dev.)}" "\multicolumn{1}{l}{Most radical candidate (std.dev.)}") fmt(2 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	drop(*) /// 
	prehead("") ///
	posthead("\hline") ///
	prefoot("Candidate radicalism distribution\\") ///
	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 and moderate candidates. " ///
	"The unit of observation is a municipality $ \times $ candidate. " ///
	"Standard errors clustered at the municipality level in parentheses. " ///
	"Panel A: Reduced-form estimates with respect to the degree of a candidate's radical discourse; " ///
	"Panel B: 2SLS estimates. " ///
	"Each column presents the estimation for a different election. " ///
	"The radicalism measure is constructed as the share of quasi-sentences with a negative tone " ///
	"from the Comparative Manifesto Project \citep{Schmitt2018}. " ///
	"The radicalism measure has been standardized and re-scaled to take a value of 0 for the most moderate candidate within an election. " ///
	"All specifications include a candidate-specific 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 with eligible births as the exogenous instrument. " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///	
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
