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

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

**** REPLICATION OF TABLE C10 ****

clear all
set mem 2g
set more off

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

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

// Import data

use $data\EEREV-D-21-00004_Data_Municip_Other.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"
global demog_chara 			"lpop_year perc_fore $pop"
global socec_aspec 			"perc_nodip perc_bacplus perc_bluecollar perc_chom lrev_median lrev_sd"

// Control vectors

global sigma				"p_french_name lpop_1936 $geogr_endow"
global w 					"$demog_chara $socec_aspec"
global dialect 				""

// Controls vector

global rdd2 				"rdd_lat rdd_lon rdd_lat_2 rdd_lon_2 rdd_lat_lon"

// Prepare sample

g sample=1*(pop_1936<20000)

// Radical-Right

foreach year in 1995 2002 2007 2012 2017{
	
	reghdfe perc_voixexd_ins age ///
		$sigma $w $rdd2 ///
		if annee==`year' & sample==1, cluster(ct) ///
		a(water ct) keepsing
		
	estimates store P`year'T1_VOTE
	qui sum perc_voixexd_ins if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}

// Abstention

foreach year in 1995 2002 2007 2012 2017{
	
	reghdfe perc_bna_ins age ///
		$sigma $w $rdd2 /// 
		if annee==`year' & sample==1, cluster(ct) ///
		a(water ct) keepsing
		
	estimates store P`year'T1_ABST
	qui sum perc_bna_ins if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}

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

// Fixed effects

estfe . P*T1*, labels(ct "\textit{Canton} FE")
return list

// Labels

la var lpop_year 	"\\ Log population"
la var perc_male 	"[0.3em] Male (\%)"
la var age_h		"[0.3em] Male age"
la var age			"[0.3em] Average age"

// Table manually modified

/*

estout P*T1_VOTE ///
	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(lpop_year perc_male age) ///
	order(lpop_year perc_male age) ///
	stats(mean_y, lab("Mean dep. variable") fmt(2)) ///
	title(Compositional effects: Age, gender, and voting behavior (municipal evidence)) ///
	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{Election year}} &\multicolumn{1}{c}{1995}  &\multicolumn{1}{c}{2002} &\multicolumn{1}{c}{2007} &\multicolumn{1}{c}{2012} &\multicolumn{1}{c}{2017}\\" ///
	"\cmidrule(lr){2-6}" ///
	"&\multicolumn{5}{c}{Panel A: OLS Estimates. Dep. Variable: Radical right-wing vote (\% of registered)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")
	
estout P*T1_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(lpop_year perc_male age) ///
	order(lpop_year perc_male age) ///
	prehead("%\hline" ///
	"\cmidrule(lr){2-6}" ///
	"& \multicolumn{5}{c}{Panel B: OLS Estimates. Dep. Variable: Abstention (\% of registered)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("")

estout P*T1_ABST ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N N_clust, lab("Observations" "Clusters") fmt(%9.0fc %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	drop(*) ///	
	indicate( /// 	
	"Historical controls vector = lpop_1936" ///
	"Contemp. controls vector = perc_chom" ///
	"Canton FE = 0.ct" ///
	, labels(Yes )) ///
	prehead("\\ Lat-lon polynomial & 2nd & 2nd & 2nd & 2nd & 2nd \\ " ///
	"%Sample restriction (1936 pop) & 20k inh. & 20k inh. & 20k inh. & 20k inh. & 20k inh. \\ ") ///
	posthead("") ///
	prefoot("\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"OLS estimates of the effect of municipality size, gender composition, and age on support for radical right-wing candidates and on abstention. " ///
	"The unit of observation is a municipality. " ///
	"Municipalities from Alsace and Moselle, as well as municipalities with more than 20,000 inhabitants in 1936 are excluded from the sample. " ///
	"Standard errors clustered at the canton level in parentheses. " ///
	"Panel A: OLS estimates with radical right-wing vote as the outcome; " ///
	"Panel B: OLS estimates with abstention as the outcome. " ///
	"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 $). " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///	
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

*/

cap log close
