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

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

**** REPLICATION OF TABLE A2 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. DEMOGRAPHICS REGRESSIONS
	2. HUMAN CAPITAL REGRESSIONS
	3. TABLE FOR PAPER
*/

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

// Import data

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

// Macros

global geogr_endow 			"water lelevation_mean lelevation_std ldist_de"
global demog_chara 			""
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 rdd2 				"rdd_lat rdd_lon rdd_lat_2 rdd_lon_2 rdd_lat_lon"

// Regressions

foreach year in 1965{
foreach var in lpop_year lpop_male perc_male age age_h age_f{ 
    
	ivreghdfe `var' (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, cluster(ct_1936_enc) ///
		a(borderfe $dialect) partial($sigma $w)
	estimates store demo_`var', title(`year')
	scalar f = e(rkf)
	estadd scalar F_fs=f
	qui sum `var' if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}
}

****************************************
***** 2. HUMAN CAPITAL REGRESSIONS *****
****************************************

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

// 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 rdd2 				"rdd_lat rdd_lon rdd_lat_2 rdd_lon_2 rdd_lat_lon"

// Regressions

foreach year in 1965{
foreach var in eduyrs perc_bacplus perc_sup perc_bluecollar perc_chom lrev_median{
    
	ivreghdfe `var' (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, cluster(ct_1936_enc) ///
		a(borderfe $dialect) partial($sigma $w)
	estimates store hc_`var', title(`year')
	scalar f = e(rkf)
	estadd scalar F_fs=f
	qui sum `var' if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
}
}

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

// Fixed effects

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

// Labels

la var perc_i_full "\\ Conscription proxy (\%)"

// Table

estout demo* ///
	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_i_full) ///
	order(perc_i_full) ///
	stats(mean_y F_fs, lab("\\ Mean dep. variable" "First-stage $ F $-statistic") fmt(2 2)) ///
	title(Abstention and the radical right-wing vote: Compositional effects) ///
	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)}\\" ///   
	"\cmidrule(lr){2-7}" ///
	"&\multicolumn{6}{c}{Panel A: 2SLS Estimates. Demographic structure (1965)}\\" ///
	"\cmidrule(lr){2-7}" ///
	"\multicolumn{1}{l}{\textit{Dep. variable}}	&\multicolumn{3}{c}{Population}	&\multicolumn{3}{c}{Age structure}\\" ///
	"\cmidrule(lr){2-4} \cmidrule(lr){5-7}" ///
	"		&\multicolumn{1}{c}{Log} &\multicolumn{1}{c}{Log Male} 	&\multicolumn{1}{c}{Male (\%)} 	&\multicolumn{1}{c}{Average} &\multicolumn{1}{c}{Male} 	&\multicolumn{1}{c}{Female} \\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

estout hc* ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y F_fs, lab("\\ Mean dep. variable" "First-stage $ F $-statistic") fmt(2 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-7}" ///
	"&\multicolumn{6}{c}{Panel B: 2SLS Estimates. Human capital (1965)}\\" ///
	"\cmidrule(lr){2-7}" ///
	"\multicolumn{1}{l}{\textit{Dep. variable}}	&\multicolumn{3}{c}{Education}	&\multicolumn{3}{c}{Employment \& income}\\" ///
	"\cmidrule(lr){2-4} \cmidrule(lr){5-7}" ///
	"		&\multicolumn{1}{c}{Years} &\multicolumn{1}{c}{High school}	&\multicolumn{1}{c}{University}	&\multicolumn{1}{c}{Blue collar} &\multicolumn{1}{c}{Unemployment} 	&\multicolumn{1}{c}{Log income} \\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("")

estout hc* ///
	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(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 \\ ") ///
	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 population, age, education, and employment outcomes in 1965. " ///
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at the canton level in parentheses. " ///
	"Panel A: 2SLS estimates for population and age; the contemporary controls vector does not include any demographic characteristics. " ///
	"Panel B: 2SLS estimates for education and employment; the contemporary controls vector does not include any socioeconomic characteristics. " ///
	"Each column presents the estimation for a different outcome. " ///
	"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