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

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

**** REPLICATION OF TABLE C9 ****

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

// Regressions

rename age age_all

foreach year in 1965 1969 1974 1995 2002 2007 2012 2017{
foreach var in lpop_year lpop_male perc_male age_all 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 `var'_`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. TABLE FOR PAPER *****
******************************

// Fixed effects

estfe . lpop_year* lpop_male* perc_male* age_all* age_h* age_f*, labels(dialect_lux "Historical dialects")
return list

// Labels

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

// Table

estout lpop_year* ///
	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, lab("Mean dep. variable") fmt(2)) ///
	title(Compositional effects: Effects on population and age) ///
	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}\\" ///
	"\cmidrule(lr){2-9}" ///
	"&\multicolumn{8}{c}{Panel A: 2SLS Estimates. Dep. Variable: Log population}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

estout lpop_male* ///
	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: Log male population}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

estout perc_male* ///
	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: Male (\%)}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

estout age_all* ///
	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 D: 2SLS Estimates. Dep. Variable: Average age}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

estout age_h* ///
	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 E: 2SLS Estimates. Dep. Variable: Male average age}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("\\")

estout age_f* ///
	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 F: 2SLS Estimates. Dep. Variable: Female average age}\\") ///
	posthead("\hline") ///
	prefoot("") ///
	postfoot("")

estout age_h* ///
	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 population, age, education, and employment outcomes. " ///
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at the canton level in parentheses. " ///
	"Panel A: 2SLS estimates for log population; " ///
	"Panel A: 2SLS estimates for log male population; " ///
	"Panel A: 2SLS estimates for fraction of males; " ///
	"Panel A: 2SLS estimates for average age; " ///
	"Panel A: 2SLS estimates for average male age; " ///
	"Panel A: 2SLS estimates for average female age. " ///
	"Each column presents the estimation for a different election. " ///
	"The contemporary controls vector does not include any demographic characteristics. " ///
	"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

