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

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

**** REPLICATION OF FIGURE A1 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. REGRESSIONS
	2. COEFFICIENT GRAPH
*/

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

// Import Municipality 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"

// Rdd

global rdd1 				"rdd_lat rdd_lon"
global rdd2 				"rdd_lat rdd_lon rdd_lat_2 rdd_lon_2 rdd_lat_lon"
global rdd3 				"rdd_lat rdd_lon rdd_lat_2 rdd_lon_2 rdd_lat_lon rdd_lat_3 rdd_lon_3 rdd_lat_2_lon rdd_lat_lon_2"

// Regressions

forvalues i=10(1)20{

	cap drop sample
	g sample=1*(perc_e_1908_1927!=. & dist_d5767<=`i')

	// 1965-1969 FOR TABLE

	foreach year in 1969{
		
		recode perc_voixexd_ins (.=0) if annee==`year'
		
		reg perc_voixexd_ins perc_i_full if annee==`year' & sample==1, cluster(ct_1936_enc)
		estimates store P`year'T1_VOTE`i', 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 /// 
			$sigma $w $rdd2 /// 
			if annee==`year' & sample==1, cluster(ct_1936_enc) ///
			a(borderfe $dialect pop_jew water) partial($sigma $w)
			
		estimates store P`year'T1_VOTE`i'
		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 /// 
			$sigma $w $rdd2 /// 
			if annee==`year' & sample==1, cluster(ct_1936_enc) ///
			a(borderfe $dialect pop_jew water) partial($sigma $w)
			
		estimates store P`year'T1_ABST`i'
		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
		
	}
}

********************************
***** 2. COEFFICIENT GRAPH *****
********************************

foreach year in 1965 1969 1974 1995 2002 2007 2012 2017{
	
	la var perc_i_full " "
	
	coefplot P`year'T1_VOTE*, keep(perc_i_full) vertical levels(95) ciopts(recast(rcap) lc(gs13)) leg(off) ///
		title("Radical right", ring(0)) ///
		mlabel mlabsize(small) format(%9.2f) mlabposition(12) mlabcolor(navy) mlabgap(*2) mcolor(navy navy navy) /// 
		yline(0, lpattern(dash)) ylabel(, angle(0) format(%9.1f)) /// 
		ylabel(-3(1)3, angle(0) format(%9.0f)) ///
		ytitle("2SLS Coefficient (95% C.I.)") xtitle("") ///
		text(-3.4 0.584 "10 km" -3.4 1 "15 km" -3.4 1.416 "20 km" ) ///
		graphregion(color(white)) name(vote, replace) nodraw

	la var perc_i_full " "
	
	coefplot P`year'T1_ABST*, keep(perc_i_full) vertical levels(95) ciopts(recast(rcap) lc(gs13)) leg(off) ///
		title("Abstention", ring(0)) ///
		mlabel mlabsize(small) format(%9.2f) mlabposition(12) mlabcolor(navy) mlabgap(*2) mcolor(navy navy navy) /// 
		yline(0, lpattern(dash)) ylabel(, angle(0) format(%9.1f)) /// 
		ylabel(-3(1)3, angle(0) format(%9.0f)) ///
		ytitle("2SLS Coefficient (95% C.I.)") xtitle("") legend(off) ///
		text(-3.4 0.584 "10 km" -3.4 1 "15 km" -3.4 1.416 "20 km" ) ///
		graphregion(color(white)) name(abst, replace) nodraw

	graph combine vote abst /// 
		, c(3) graphregion(color(white)) ycommon imargin(vsmall) title("`year' Election") name(g`year', replace)
	graph export "$results\EEREV-D-21-00004_FigureA1_`year'.png", replace width(5400) height(3000)
	
}

cap log close
