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

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

**** REPLICATION OF TABLE 3 ****

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

keep if annee==1965

// 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 		"perc_fore $pop"
global socec_aspec 		"perc_bacplus perc_bluecollar perc_chom lrev_median lrev_sd"

// Control vectors

global sigma 			"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"

// First column

ivreghdfe perc_i_full perc_e_1908_1927 if annee==1965 & sample==1, cluster(ct_1936_enc)
estimates store FS1
test perc_e_1908_1927
estadd scalar F_fs=r(chi2) //
sum perc_i_full  if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Second column

ivreghdfe perc_i_full perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 if annee==1965 & sample==1, cluster(ct_1936_enc)
lincom perc_e_1908_1927+perc_b_1903_1912 //
lincom perc_e_1908_1927+perc_b_1913_1922 //
lincom perc_e_1908_1927+perc_b_1923_1932 //
estimates store FS2
test perc_e_1908_1927
estadd scalar F_fs=r(chi2) //
sum perc_i_full  if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Third column

ivreghdfe perc_i_full perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 $rdd2 if annee==1965 & sample==1, cluster(ct_1936_enc) a(borderfe $dialect) 
lincom perc_e_1908_1927+perc_b_1903_1912 //
lincom perc_e_1908_1927+perc_b_1913_1922 //
lincom perc_e_1908_1927+perc_b_1923_1932 //
estimates store FS3
test perc_e_1908_1927
estadd scalar F_fs=r(F)
sum perc_i_full  if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Fourth column

ivreghdfe perc_i_full perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 $rdd2 $sigma perc_prot_church if annee==1965 & sample==1, cluster(ct_1936_enc) a(borderfe $dialect pop_jew water) partial($sigma)
lincom perc_e_1908_1927+perc_b_1903_1912 //
lincom perc_e_1908_1927+perc_b_1913_1922 //
lincom perc_e_1908_1927+perc_b_1923_1932 //
estimates store FS4
test perc_e_1908_1927
estadd scalar F_fs=r(F)
sum perc_i_full  if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Fifth column

ivreghdfe perc_i_full perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932 $rdd2 $sigma $w perc_prot_church lpop_counter if annee==1965 & sample==1, cluster(ct_1936_enc) a(borderfe $dialect pop_jew water) partial($sigma $w)
lincom perc_e_1908_1927+perc_b_1903_1912 //
lincom perc_e_1908_1927+perc_b_1913_1922 //
lincom perc_e_1908_1927+perc_b_1923_1932 //
estimates store FS5
test perc_e_1908_1927
estadd scalar F_fs=r(F)
sum perc_i_full  if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

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

// Fixed effects

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

// Labels

la var perc_e_1908_1927 	"\\ Eligible births (\%)"
la var perc_b_1903_1912 	"[0.3em] Born 1903-1912 (\%)"
la var perc_b_1913_1922 	"[0.3em] Born 1913-1922 (\%)"
la var perc_b_1923_1932 	"[0.3em] Born 1923-1932 (\%)"

// First-Stage

estout FS1 FS2 FS3 FS4 FS5 ///
	using "$results\\$program.tex", replace style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(F_fs, lab("\\ First-stage $ F $-statistic") fmt(2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932) ///
	order(perc_e_1908_1927 perc_b_1903_1912 perc_b_1913_1922 perc_b_1923_1932) ///
	title(Estimation strategy: First-stage estimates) ///
	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)}\\" ///
	"\cmidrule(lr){2-6}" ///
	"\multicolumn{1}{l}{\textit{Specification}}&\multicolumn{1}{c}{No controls} &\multicolumn{1}{c}{Fertility}  &\multicolumn{1}{c}{Lat-lon poly} &\multicolumn{1}{c}{Historical} &\multicolumn{1}{c}{Historical and}\\" ///
	" &\multicolumn{1}{c}{} &\multicolumn{1}{c}{controls}  &\multicolumn{1}{c}{and dialect} &\multicolumn{1}{c}{controls} &\multicolumn{1}{c}{contemporary}\\" ///
	"\cmidrule(lr){2-6}" ///
	"& \multicolumn{5}{c}{First-Stage Estimates. Dep. Variable: Conscription proxy (\%)}\\") ///
	posthead("\hline") //

estout FS1 FS2 FS3 FS4 FS5 ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y N N_clust, lab("Mean dep. variable" "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" ///
	"Historical controls = perc_prot_church" ///
	"Contemporary controls (1965) = lpop_counter" ///
	, labels(Yes )) ///
	title(First-stage estimates) ///
	posthead("\\ Lat-lon polynomial &  &  & 2nd & 2nd & 2nd \\ ") ///
	prefoot("\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"First-stage estimates of the effect of the draft rule on Wehrmacht conscription. " ///
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at the canton level in parentheses. " ///
	"Columns (3) to (5) 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. " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///	
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
