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

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

**** REPLICATION OF TABLE 7 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. PREPARE DATA
	2. WITHIN ELECTION
	3. ACROSS ELECTION
	4. ABSTENTION
	5. TABLE FOR PAPER
*/

***************************
***** 1. PREPARE DATA *****
***************************

// Import Municipality data

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

// Reshape

drop if sample==0
drop sample

reshape long voix_, i(com dep annee) j(candidate) string
drop if voix_==.
rename voix_ voix

// Merge with Candidate data

merge m:1 annee candidate using $data\EEREV-D-21-00004_Data_Candidates
tab candidate annee if _merge==1
rename _merge sample

// Generate vote shares

g perc_exp=(voix*100)/exprimes 
g perc_ins=(voix*100)/inscrits
format perc_* %9.2f

// Get Inverse polar for abstention (time invariant)

foreach var in neg nat aut{
	bysort annee: egen min=min(inv_`var'_P)
	replace inv_`var'_P=min if sample==1
	drop min
}

// Fixed effects

recode party (.=-999) if sample==1 // Abstention

egen com_year=group(com annee)
egen com_party=group(com party)
egen cand_year_border=group(cand_year borderfe)
egen party_year_border=group(party annee borderfe)

// Macros

global ctrl_neg_C 			"c.lpop_counter#c.neg_C c.perc_male_counter#c.neg_C c.perc_disp_1946#c.neg_C" 
global ctrl_inv_neg_P		"c.lpop_counter#c.inv_neg_P c.perc_male_counter#c.inv_neg_P c.perc_disp_1946#c.inv_neg_P" 

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"
global w 					"$demog_chara $socec_aspec"

******************************
***** 2. WITHIN ELECTION *****
******************************

cap drop trend
g trend=cand_year_border

// Within election -> Second-Stage

ivreghdfe perc_ins ///
	(c.perc_i_full#c.neg_C = c.perc_e_1908_1927#c.neg_C) ///	
	c.perc_b_1903_1912#c.neg_C c.perc_b_1913_1922#c.neg_C c.perc_b_1923_1932#c.neg_C ///
	$ctrl_neg_C ///
	if sample==3, cluster(com_year) a(com_year trend)
estimates store Pneg_C_annee_SS_ctrl
scalar f = e(rkf)
estadd scalar F_fs=f
qui sum perc_ins if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Within election -> Second-Stage, controlling for other aspects

ivreghdfe perc_ins ///
	(c.perc_i_full#c.neg_C c.perc_i_full#c.aut_C c.perc_i_full#c.nat_C = c.perc_e_1908_1927#c.neg_C c.perc_e_1908_1927#c.aut_C c.perc_e_1908_1927#c.nat_C) ///	
	c.perc_b_1903_1912#c.neg_C c.perc_b_1913_1922#c.neg_C c.perc_b_1923_1932#c.neg_C ///
	c.perc_b_1903_1912#c.aut_C c.perc_b_1913_1922#c.aut_C c.perc_b_1923_1932#c.aut_C /// 
	c.perc_b_1903_1912#c.nat_C c.perc_b_1913_1922#c.nat_C c.perc_b_1923_1932#c.nat_C /// 
	$ctrl_neg_C ///
	if sample==3, cluster(com_year) a(com_year trend)
estimates store Pneg_C_annee_SS_pos
scalar f = e(rkf)
estadd scalar F_fs=f
scalar f_under=e(idstat)
estadd scalar F_u=f_under
qui sum perc_ins if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

******************************
***** 3. ACROSS ELECTION *****
******************************

cap drop trend
g trend=party_year_border

// Within party -> Second stage

ivreghdfe perc_ins ///
	(c.perc_i_full#c.neg_C c.perc_i_full#c.inv_neg_P = c.perc_e_1908_1927#c.neg_C c.perc_e_1908_1927#c.inv_neg_P) ///
	c.perc_b_1903_1912#c.neg_C c.perc_b_1913_1922#c.neg_C c.perc_b_1923_1932#c.neg_C ///
	c.perc_b_1903_1912#c.inv_neg_P c.perc_b_1913_1922#c.inv_neg_P c.perc_b_1923_1932#c.inv_neg_P ///
	$w /// 
	$ctrl_neg_C $ctrl_inv_neg_P ///
	if sample==3, cluster(com_year) a(com_party trend) partial($w)
estimates store Pneg_C_party_SS_ctrl
scalar f = e(rkf)
estadd scalar F_fs=f
scalar f_under=e(idstat)
estadd scalar F_u=f_under
qui sum perc_ins if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Within party -> Second stage, controlling for other aspects

ivreghdfe perc_ins ///
	(c.perc_i_full#c.neg_C c.perc_i_full#c.inv_neg_P ///
	c.perc_i_full#c.aut_C c.perc_i_full#c.inv_aut_P ///
	c.perc_i_full#c.nat_C c.perc_i_full#c.inv_nat_P ///
	= c.perc_e_1908_1927#c.neg_C c.perc_e_1908_1927#c.inv_neg_P ///
	c.perc_e_1908_1927#c.aut_C c.perc_e_1908_1927#c.inv_aut_P ///
	c.perc_e_1908_1927#c.nat_C c.perc_e_1908_1927#c.inv_nat_P) ///
	c.perc_b_1903_1912#c.neg_C c.perc_b_1913_1922#c.neg_C c.perc_b_1923_1932#c.neg_C /// 
	c.perc_b_1903_1912#c.aut_C c.perc_b_1913_1922#c.aut_C c.perc_b_1923_1932#c.aut_C /// 
	c.perc_b_1903_1912#c.nat_C c.perc_b_1913_1922#c.nat_C c.perc_b_1923_1932#c.nat_C /// 
	c.perc_b_1903_1912#c.inv_neg_P c.perc_b_1913_1922#c.inv_neg_P c.perc_b_1923_1932#c.inv_neg_P ///
	c.perc_b_1903_1912#c.inv_aut_P c.perc_b_1913_1922#c.inv_aut_P c.perc_b_1923_1932#c.inv_aut_P ///
	c.perc_b_1903_1912#c.inv_nat_P c.perc_b_1913_1922#c.inv_nat_P c.perc_b_1923_1932#c.inv_nat_P ///
	$w /// 
	$ctrl_neg_C $ctrl_inv_neg_P ///
	if sample==3, cluster(com_year) a(com_party trend) partial($w)
estimates store Pneg_C_party_SS_pos
scalar f = e(rkf)
estadd scalar F_fs=f
scalar f_under=e(idstat)
estadd scalar F_u=f_under
qui sum perc_ins if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

*************************
***** 4. ABSTENTION *****
*************************

// Abstention -> Second-Stage

ivreghdfe perc_ins ///
	(c.perc_i_full#c.inv_neg_P = c.perc_e_1908_1927#c.inv_neg_P) ///
	c.perc_b_1903_1912#c.inv_neg_P c.perc_b_1913_1922#c.inv_neg_P c.perc_b_1923_1932#c.inv_neg_P ///
	$w /// 
	$ctrl_neg_P $ctrl_inv_neg_P ///
	if sample==1, cluster(com) a(com_party trend) partial($w)
estimates store Pneg_A_party_SS_ctrl
scalar f = e(rkf)
estadd scalar F_fs=f
qui sum perc_ins if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

// Abstention -> Second-Stage, controlling for other aspects

ivreghdfe perc_ins ///
	(c.perc_i_full#c.inv_neg_P ///
	c.perc_i_full#c.inv_aut_P ///
	c.perc_i_full#c.inv_nat_P ///
	= c.perc_e_1908_1927#c.inv_neg_P ///
	c.perc_e_1908_1927#c.inv_aut_P ///
	c.perc_e_1908_1927#c.inv_nat_P) ///
	c.perc_b_1903_1912#c.inv_neg_P c.perc_b_1913_1922#c.inv_neg_P c.perc_b_1923_1932#c.inv_neg_P ///
	c.perc_b_1903_1912#c.inv_aut_P c.perc_b_1913_1922#c.inv_aut_P c.perc_b_1923_1932#c.inv_aut_P ///
	c.perc_b_1903_1912#c.inv_nat_P c.perc_b_1913_1922#c.inv_nat_P c.perc_b_1923_1932#c.inv_nat_P ///
	$w /// 
	$ctrl_neg_P $ctrl_inv_neg_P ///
	if sample==1, cluster(com) a(com_party trend) partial($w) // keepsing old
estimates store Pneg_A_party_SS_pos
scalar f = e(rkf)
estadd scalar F_fs=f
scalar f_under=e(idstat)
estadd scalar F_u=f_under
qui sum perc_ins if e(sample)
scalar mean_y=r(mean)
estadd scalar mean_y

******************************
***** 5. TABLE FOR PAPER *****
******************************

// Fixed effects

estfe . Pneg*, labels(com_year "Municipality $ \times $ election FE" com_party "Municipality $ \times $ party FE" trend "Candidate FE")
return list

// Labels

la var perc_i_full		"[0.3em] Conscription (\%)"
la var neg_C 			"Radical"
la var aut_C 			"Authoritarian"
la var nat_C 			"Nationalist"

// Coeffcients

estout 	Pneg_C_annee_SS_ctrl Pneg_C_annee_SS_pos ///
		Pneg_C_party_SS_ctrl Pneg_C_party_SS_pos ///  
		Pneg_A_party_SS_ctrl Pneg_A_party_SS_pos /// 
	using "$results\\$program.tex", replace style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(mean_y F_fs F_u N N_clust, lab("Mean dependent variable" "First-stage $ F $-statistic" "Underidentification $ F $-statistic" "Observations" "Clusters") fmt(2 2 2 %9.0fc %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(c.perc_i_full#c.neg_C c.perc_i_full#c.inv_neg_P c.perc_i_full#c.aut_C c.perc_i_full#c.inv_aut_P c.perc_i_full#c.nat_C c.perc_i_full#c.inv_nat_P) ///
	order(c.perc_i_full#c.neg_C c.perc_i_full#c.inv_neg_P c.perc_i_full#c.aut_C c.perc_i_full#c.inv_aut_P c.perc_i_full#c.nat_C c.perc_i_full#c.inv_nat_P) ///
	varlabels(c.perc_i_full#c.neg_C "Conscription (\%) $ \times $ Radical" c.perc_i_full#c.inv_neg_P "[0.3em] Conscription (\%) / $ \Delta \text{Radical} $" ///
	c.perc_i_full#c.inv_aut_P "[0.3em] Conscription (\%) / $ \Delta \text{Authoritarian} $" c.perc_i_full#c.inv_nat_P "[0.3em] Conscription (\%) / $ \Delta \text{Nationalist} $") ////
	title(From abstention to radical support: Second-stage estimates) /// 
	indicate( ///
	"\\ Candidate-border segment FE = 0.trend" /// 
	"Election $ \times $ Municipality FE = 0.com_year" ///
	"Party $ \times $ Municipality FE = 0.com_party" /// 
	"Contemporary controls = c.lpop_counter#c.inv_neg_P" ///
	, labels(Yes )) ///
	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}{l}{\textit{Dep. Variable}} &\multicolumn{4}{c}{Candidate vote share} &\multicolumn{2}{c}{Abstention}\\" ///	
	"\cmidrule(lr){2-5} \cmidrule(lr){6-7}" ///
	"\multicolumn{1}{l}{\textit{Specification}} &\multicolumn{2}{c}{2SLS Within election} &\multicolumn{2}{c}{2SLS Across elections} &\multicolumn{2}{c}{2SLS Across elections}\\") ///
	posthead("\hline" ///
	"\\") ///
	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 support for radical candidates and abstention across space and time (Equation [\ref{2SLS_MODEL}]). " ///
	"The unit of observation is a municipality $ \times $ election $ \times $ candidate. " ///
	"Standard errors clustered at the municipality $ \times $ election in parentheses. " ///
	"Columns (1) and (2): results within a municipality $ \times $ election (across candidates); " ///
	"Columns (3) to (6): results within a municipality $ \times $ party (across time). " ///
	"Columns (1) and (2): 2SLS estimates for candidate vote shares within municipality and election (across candidates); " ///
	"Columns (3) and (4): 2SLS estimates for candidate vote shares within municipality and party (across time); " ///
	"Columns (5) and (6): 2SLS estimates for abstention and invalid ballots within municipality and party (across time). " ///
	"First-stage F-statistic is the Kleibergen-Paap rk Wald F-statistic of the first-stage estimation with Eligible births (\%) $ \times $ Radical and " ///
	"Eligible births (\%) / $ \Delta \text{Radical} $ as the exogenous instruments. " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%. " ///	
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable} " ///
	"\end{center}" ///
	"\end{table}")

cap log close
