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

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

**** REPLICATION OF TABLE B2 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. CONTROLS TABLE
*/

*****************************
***** 1. CONTROLS TABLE *****
*****************************

// Import data

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

keep if sample==1
keep if annee==1969

global dialect 		"dialect_rhe dialect_pal dialect_als dialect_lor"
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"

// Shorten labels

la var perc_i_full 			"\\ Conscripted (\%)" 
la var perc_e_1908_1927 	"[0.3em] Eligible births (\%)"
la var perc_b_1903_1912 	"[0.3em] Births 1903-1912 (\%)"
la var perc_b_1913_1922 	"[0.3em] Births 1913-1922 (\%)"
la var perc_b_1923_1932 	"[0.3em] Births 1923-1932 (\%)"
la var perc_prot_church 	"[0.3em] Protestant churches (\%)" 
la var pop_jew 				"[0.3em] Synagogue (binary)" 
la var p_french_name		"[0.3em] French name at birth (\%)"
la var lpop_1936 			"[0.3em] Population 1936 (Log)"
la var perc_fore_1936		"[0.3em] Male foreigners in 1936 (\%)"
la var perc_dial_1936 		"[0.3em] Dialect-speaking in 1936 (\%)" 
la var perc_disp_1946 		"[0.3em] Displaced in 1946 (\%)" 
la var water 				"[0.3em] Waterway (binary)" 
la var lelevation_mean 		"[0.3em] Elevation (Log m.)"
la var lelevation_std 		"[0.3em] Elevation std.dev. (Log m.)"
la var ldist_de				"[0.3em] Distance to Germany (Log km)"
la var perc_droi_1936_ins	"[0.3em] Right-wing in 1936 (\% registered)"
la var dialect_rhe 			"[0.3em] Dialect: Rhine Franconian (binary)"

la var dialect_pal 			"[0.3em] \multicolumn{1}{l}{South Franconian (binary)}"
la var dialect_als 			"[0.3em] \multicolumn{1}{l}{Alsatian (binary)}"
la var dialect_lor 			"[0.3em] \multicolumn{1}{l}{Lorrain (binary)}"

// Get stats

estpost tabstat ///
	perc_i_full perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 $sigma $dialect if annee==1969 ///
	, s(N mean sd min max p5 p50 p95) columns(statistics) //
	
matrix N=e(count)
matrix m=e(Mean)
matrix s=e(SD)
matrix i=e(Min)
matrix a=e(Max)
matrix x=e(p5)
matrix y=e(p50)
matrix z=e(p95)

matrix obs = N'
matrix mean=m'
matrix sd=s'
matrix min=i'
matrix max=a'
matrix p5=x'
matrix p50=y'
matrix p95=z'

matrix b = obs, mean, sd, min, p5, p50, p95, max
matrix list b

// Export table

estout matrix(b, fmt(%9.0fc 2 2 2 2 2 2 2)) using ///
	"$results\\$program.tex", replace style(tex) type label ///
	unstack collabels(none) ///
	mlabels(, none) ///
	msign(--) ///
	title(Covariates: Historical control variables) ///
	prehead("\begin{table}[t!]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{scriptsize}" ///
	"\caption{@title}" ///
	"\label{$program}"  /// 
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{8}{c}@{}}" ///
	"\hline" "\hline" ///
	"&\multicolumn{3}{c}{Statistics} &\multicolumn{5}{c}{Distribution}\\" ///
	"\cmidrule(lr){2-4} \cmidrule(lr){5-9}" ///
	"\textit{Variable}	&\multicolumn{1}{c}{Obs.} &\multicolumn{1}{c}{Mean}  &\multicolumn{1}{c}{Std.Dev.}  &\multicolumn{1}{c}{Min}  &\multicolumn{1}{c}{5th pctile}   &\multicolumn{1}{c}{Median}  &\multicolumn{1}{c}{95th pctile}   &\multicolumn{1}{c}{Max}\\") ///
	posthead("\hline" ///
	"") ///
	prefoot("\\") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" ///
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 	
	"Historical covariates used in Section \ref{VOTE}. " ///
	"The unit of observation is a municipality (variables are time-invariant). " ///
	"See Online Appendix \ref{DATA_COVARIATES} for the construction of the variables. " ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
