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

cap log close
*cap log using "$log\log_$program$today", replace // The log-file for this program is larger than 75 MB

**** REPLICATION OF TABLE A4 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. REGION FALSIFICATION
	2. GENDER FALSIFICATION
	3. TABLE FOR PAPER
*/

***********************************
***** 1. REGION FALSIFICATION *****
***********************************

// Get empty data

use $data\EEREV-D-21-00004_Data_Interreg.dta, clear
g dep_comb=""
keep dep_comb
duplicates drop
saveold $data\tmp.dta, replace

// Import data

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

// Reduced-Form

drop if birthyr==.
keep if birthyr>=1908 & birthyr<=1927
keep if sexe==1

qui reghdfe born_1908_1913 if birthyr>=1908 & birthyr<=1927 & sexe==1, cluster(birthyr) a(i.birthyr#i.sexe i.nationalite_pop i.religion i.anciennete i.annee)
keep if e(sample)

foreach pos in confiance1 confiance2 confiance4 confiance5 confiance6 confiance9 confiance11 proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA{
	
	cap drop rowmiss ok
	egen rowmiss=rowmiss(`pos' born_1908_1913 birthyr sexe nationalite_pop religion anciennete annee)
	g ok=1*(rowmiss==0)
	
	bysort dep: egen n`pos'=sum(ok)
	g sample`pos'=1*(n`pos'>20)
	drop n`pos'
	cap drop rowmiss ok
	
}
	
saveold $data\tmp2.dta, replace

// Get combinations

use $data\tmp2.dta, clear
keep dep sample*
rename dep dep1
rename sample* sample*_1
duplicates drop
saveold $data\tmp3.dta, replace

use $data\tmp2.dta, clear
keep dep sample*
rename dep dep2
rename sample* sample*_2
duplicates drop

cross using $data\tmp3
drop if dep1>=dep2

g object=_n

reshape long dep sampleconfiance1_ sampleconfiance2_ sampleconfiance4_ sampleconfiance5_ ///
	sampleconfiance6_ sampleconfiance9_ sampleconfiance11_ sampleproximiteFN_ ///
	sampleproximiteRPR_ sampleproximitePS_ sampleproximiteUDF_ sampleproximiteECO_ ///
	sampleproximiteCOM_ sampleproximiteNA_, i(object) j(tmp)

drop tmp
rename sample*_ sample*

reshape long sample, i(object dep) j(var) string

bysort object var: egen rank=rank(dep)

reshape wide dep sample, i(object var) j(rank)
drop if sample1==0
drop if sample2==0

drop object sample1 sample2

duplicates drop

saveold $data\tmp3.dta, replace

// Run regressions to get coefficients

foreach pos in confiance1 confiance2 confiance4 confiance5 confiance6 confiance9 confiance11 proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA{ // 

	use $data\tmp3.dta, clear
	keep if var=="`pos'"
	levelsof dep1, local(levels1)
	foreach o of local levels1{		

	use $data\tmp3.dta, clear
	keep if var=="`pos'"
	keep if dep1==`o'
	
	levelsof dep2, local(levels2)
	foreach d of local levels2{	
	
		use $data\tmp2.dta, clear
		
		keep if dep==`o' | dep==`d'
			
		g tmp1=runiform()
		sum tmp1
		tab dep if `pos'!=., sum(`pos')
		g mean=r(mean)
		cap drop alsace
		g alsace=1*(dep==`o') if mean>=.5
		replace alsace=1*(dep==`d') if mean<.5
		g control=1-alsace

		egen cluster=group(birthyr dep)

		cap ivreghdfe `pos' alsace c.born_1908_1913#c.alsace ///
			if birthyr>=1908 & birthyr<=1927 & sexe==1, cluster(cluster) a(i.birthyr#i.sexe i.nationalite_pop i.religion i.anciennete i.annee)
		keep if e(sample)
		
		scalar N=e(N)
		
		tab alsace if alsace==1
		scalar N_treat=r(N)
			
		tab alsace if alsace==0
		scalar N_control=r(N)

		parmest, saving("$data\tmp1.dta", replace) level(90)

		use $data\tmp1.dta, clear

		g obs=N
		g obs_t=N_treat
		g obs_c=N_control
		g dep_comb="`o'_`d'"
		g var="`pos'"
				
		append using $data\tmp.dta
		duplicates drop
		
		keep if parm=="c.born_1908_1913#c.alsace"
			
		saveold $data\tmp.dta, replace
			
	}
	}
}

// Drop AM

use $data\tmp.dta, clear

split dep_comb, p("_")
destring dep_comb1 dep_comb2, replace

drop if dep_comb1==57 | dep_comb2==57
drop if dep_comb1==67 | dep_comb2==67
drop if dep_comb1==68 | dep_comb2==68
drop dep_comb1 dep_comb2

saveold $data\tmp.dta, replace

// Run for Alsace-Moselle

foreach pos in confiance1 confiance2 confiance4 confiance5 confiance6 confiance9 confiance11 proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA{

	// Get Alsace moselle coefficient

	use $data\tmp2.dta, clear
			
	keep if dep==57 | dep==67 | dep==68
			
	egen cluster=group(birthyr alsace)

	ivreghdfe `pos' alsace c.born_1908_1913#c.alsace ///
		if birthyr>=1908 & birthyr<=1927 & sexe==1, cluster(cluster) a(i.birthyr#i.sexe i.nationalite_pop i.religion i.anciennete i.annee)
	keep if e(sample)
	
	scalar N=e(N)
			
	tab alsace if alsace==1
	scalar N_treat=r(N)
			
	tab alsace if alsace==0
	scalar N_control=r(N)

	parmest, saving("$data\tmp1.dta", replace) level(90)

	use $data\tmp1.dta, clear
	
	g obs=N
	g obs_t=N_treat
	g obs_c=N_control
	g dep_comb="57_67"
	g var="`pos'"
			
	append using $data\tmp.dta
			
	keep if parm=="c.born_1908_1913#c.alsace"
			
	saveold $data\tmp.dta, replace

}

// Difference regressions: Prepare data

use $data\tmp.dta, clear

g tmp=estimate if dep_comb=="57_67"
bysort var: egen beta=max(tmp)
drop tmp

split dep_comb, p("_")
destring dep_comb1 dep_comb2, replace
drop if dep_comb1>=dep_comb2

g w_se=1/stderr
sum w_se, d

drop if w_se>1000

foreach pos in confiance1 confiance2 confiance4 confiance5 confiance6 confiance9 confiance11 proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA{
	
	sum estimate if var=="`pos'" & dep_comb!="57_67" [aw=w_se], d
	g mean_`pos'=r(mean)
	replace estimate=estimate+mean_`pos' if var=="`pos'" & dep_comb=="57_67"
	drop mean_`pos'
	
}

saveold $data\tmp4.dta, replace

// Get Alsace-Moselle coefficient

foreach pos in confiance1 confiance2 confiance4 confiance5 confiance6 confiance9 confiance11 proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA{
    
	use $data\tmp2.dta, clear
			
	keep if dep==57 | dep==67 | dep==68
			
	egen cluster=group(birthyr alsace)

	ivreghdfe `pos' alsace c.born_1908_1913#c.alsace ///
		if birthyr>=1908 & birthyr<=1927 & sexe==1, cluster(cluster) a(i.birthyr#i.sexe i.nationalite_pop i.religion i.anciennete i.annee)
	estimates store OLS_`pos'
	qui sum `pos' if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
	
	use $data\tmp4.dta, clear
	
	g AM=1*(dep_comb=="57_67")
	
	reg estimate AM if var=="`pos'" [aw=w_se]
	estimates store G0`pos'
	
	test AM+_cons=0
	estadd scalar p=r(p) 
	sum estimate if var=="`pos'" & dep_comb!="57_67", d
	sum estimate if var=="`pos'" & dep_comb!="57_67" [aw=w_se], d // 
	estadd scalar p5=r(p5) 
	estadd scalar p95=r(p95) 
	estadd scalar mean=r(mean) 
	estadd scalar obs=r(N) 
}

***********************************
***** 2. GENDER FALSIFICATION *****
***********************************

// Import survey data

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

keep if dep_inc==1

// Clustering

egen cluster=group(birthyr alsace)

// Trust Regressions

foreach i in 1 2 4 5 6 9 11{ // 
	
	ivreghdfe confiance`i' alsace c.born_1908_1913#c.alsace ///
		if birthyr>=1908 & birthyr<=1927 & sexe==2, cluster(cluster) a(i.birthyr#i.sexe i.nationalite_pop i.religion i.anciennete i.annee) //

	estimates store W0confiance`i'
	qui sum confiance`i' if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y

}

// Fixed effects

estfe . W0confiance*, labels(nationalite_pop "Individual controls" annee "Survey year FE" birthyr#sexe "YoB $ \times $ gender FE")
return list

// Vote Regressions

foreach var in proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA{ // 

	ivreghdfe `var' alsace c.born_1908_1913#c.alsace ///
		if birthyr>=1908 & birthyr<=1927 & sexe==2, cluster(cluster) a(i.birthyr#i.sexe i.nationalite_pop i.religion i.anciennete i.annee)

	estimates store W0`var'
	qui sum `var' if e(sample)
	scalar mean_y=r(mean)
	estadd scalar mean_y
}

// Fixed effects

estfe . W0proximite*, labels(nationalite_pop "Individual controls" annee "Survey year FE" birthyr#sexe "YoB $ \times $ gender FE")
return list

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

// Labels

la var born_1908_1913 "[0.3em] Born 1908-1913" 

// Women: Vote

estout W0proximiteCOM W0proximitePS W0proximiteECO W0proximiteUDF W0proximiteRPR W0proximiteFN W0proximiteNA ///
	using "$results\\$program.tex", replace 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(3 %9.0fc %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(alsace c.born_1908_1913#c.alsace) /// 
	order(alsace c.born_1908_1913#c.alsace) ///
	title(Party proximity and trust in institutions: Falsifications exercises) ///
	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" ///
	"\cmidrule(lr){2-8}" ///
	"& \multicolumn{7}{c}{Panel A: Gender falsifications. \textit{Which party do you feel closer to, or less distant from}}\\" ///
	"\cmidrule(lr){2-8}" ///
	"\multicolumn{1}{l}{\textit{Dep. Variable}}	&\multicolumn{1}{c}{\textit{Communist}}	&\multicolumn{1}{c}{\textit{Socialist}}	&\multicolumn{1}{c}{\textit{Ecologist}}	&\multicolumn{1}{c}{\textit{Liberal}} &\multicolumn{1}{c}{\textit{Conservative}}	&\multicolumn{1}{c}{\textit{Radical right}}	&\multicolumn{1}{c}{\textit{None}}  		\\" /// 
	"\hline") ///
	posthead("\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("")

// Women: Trust

estout W0confiance1 W0confiance2 W0confiance4 W0confiance5 W0confiance6 W0confiance9 W0confiance11 ///
	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(3 %9.0fc %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(alsace c.born_1908_1913#c.alsace) /// 
	order(alsace c.born_1908_1913#c.alsace) ///
	prehead("\\") ///
	posthead("%\hline" ///
	"\cmidrule(lr){2-8}" ///
	"& \multicolumn{7}{c}{Panel B: Gender falsifications. \textit{Would you say you rather trust or distrust in}}\\" ///
	"\cmidrule(lr){2-8}" ///
	"\multicolumn{1}{l}{\textit{Dep. Variable}} 	&\multicolumn{1}{c}{\textit{Schools}}	&\multicolumn{1}{c}{\textit{Justice}} 	&\multicolumn{1}{c}{\textit{Police}}	&\multicolumn{1}{c}{\textit{Church}}	&\multicolumn{1}{c}{\textit{Army}}	&\multicolumn{1}{c}{\textit{Parties}}	&\multicolumn{1}{c}{\textit{Politicians}}  		\\" /// 
	"\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") 

// Region: Vote

estout G0proximiteCOM G0proximitePS G0proximiteECO G0proximiteUDF G0proximiteRPR G0proximiteFN G0proximiteNA ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(p5 p95, lab("\multicolumn{1}{l}{5th percentile}" "\multicolumn{1}{l}{95th percentile}") fmt(3 3)) ///
	collabels(none) wrap varwidth(36) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(AM) /// 
	varlabels(AM "\\ Born 1908-1913 $ \times $ Alsace") ///
	prehead("\\") ///
	posthead("%\hline" ///
	"\cmidrule(lr){2-8}" ///
	"& \multicolumn{7}{c}{Panel C: Region falsifications. \textit{Which party do you feel closer to, or less distant from}}\\" ///
	"\cmidrule(lr){2-8}" /// 
	"\multicolumn{1}{l}{\textit{Dep. Variable}} 	&\multicolumn{1}{c}{\textit{Schools}}	&\multicolumn{1}{c}{\textit{Justice}} 	&\multicolumn{1}{c}{\textit{Police}}	&\multicolumn{1}{c}{\textit{Church}}	&\multicolumn{1}{c}{\textit{Army}}	&\multicolumn{1}{c}{\textit{Parties}}	&\multicolumn{1}{c}{\textit{Politicians}}  		\\" /// 
	"\hline") ///
	prefoot("\\" ///
	"Placebo tests (other departments) \\") //

estout G0proximiteCOM G0proximitePS G0proximiteECO G0proximiteUDF G0proximiteRPR G0proximiteFN G0proximiteNA ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(p(fmt(%9.3f)))  ///
	stats(mean obs, lab("Mean coefficient (other departments)" "Observations (department pairs)") fmt(3 %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(AM) ///
	order(AM) ///
	varlabels(AM "\multicolumn{1}{l}{Two-tailed test $ p $ -value}") ///
	prehead("") ///
	prefoot("\hline") ///
	postfoot("")

// Region: Trust

estout G0confiance1 G0confiance2 G0confiance4 G0confiance5 G0confiance6 G0confiance9 G0confiance11 ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(p5 p95, lab("\multicolumn{1}{l}{5th percentile}" "\multicolumn{1}{l}{95th percentile}") fmt(3 3)) ///
	collabels(none) wrap varwidth(36) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(AM) /// 
	varlabels(AM "\\ Born 1908-1913 $ \times $ Alsace") ///
	prehead("\\") ///
	posthead("%\hline" ///
	"\cmidrule(lr){2-8}" ///
	"& \multicolumn{7}{c}{Panel D: Region falsifications. \textit{Would you say you rather trust or distrust in}}\\" ///
	"\cmidrule(lr){2-8}" ///
	"\multicolumn{1}{l}{\textit{Dep. Variable}} 	&\multicolumn{1}{c}{\textit{Schooling}}	&\multicolumn{1}{c}{\textit{Judicial}} 	&\multicolumn{1}{c}{\textit{Police}}	&\multicolumn{1}{c}{\textit{Church}}	&\multicolumn{1}{c}{\textit{Army}}	&\multicolumn{1}{c}{\textit{Political}}	&\multicolumn{1}{c}{\textit{Elected}}  		\\" /// 
	"	&\multicolumn{1}{c}{\textit{system}} 	&\multicolumn{1}{c}{\textit{system}}  	&\multicolumn{1}{c}{} 					&\multicolumn{1}{c}{}  					&\multicolumn{1}{c}{}				&\multicolumn{1}{c}{\textit{parties}} 	&\multicolumn{1}{c}{\textit{politicians}}	\\" /// 
	"\hline") ///
	prefoot("\\" ///
	"Placebo tests (other departments) \\") //

estout G0confiance1 G0confiance2 G0confiance4 G0confiance5 G0confiance6 G0confiance9 G0confiance11 ///
	using "$results\\$program.tex", append style(tex) type label ///
	cells(p(fmt(%9.3f)))  ///
	stats(mean obs, lab("Mean coefficient (other departments)" "Observations (department pairs)") fmt(3 %9.0fc)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels(* .1 ** .05 *** .01) ///
	keep(AM) ///
	order(AM) ///
	varlabels(AM "\multicolumn{1}{l}{Two-tailed test $ p $ -value}") ///
	prehead("") ///
	prefoot("\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"Falsifications exercises of the effect of Wehmacht eligibility on political preferences. " ///
	"Panel A: Gender falsifications with party proximity as the outcome;  " ///
	"Panel B: Gender falsifications with measures of trust in institutions are the outcome.  " ///
	"Panel C: Region falsifications with party proximity as the outcome;  " ///
	"Panel D: Region falsifications with measures of trust in institutions are the outcome.  " ///
	"Each column presents the estimation for a different party/institution.  " ///
	"Year-of-birth $ \times $ gender fixed effects are included in all specifications.  " ///
	"The unit of observation in Panels A and B is a female individual; in Panels C and D it is a department pair.  " ///
	"Standard errors clustered at year-of-birth $ \times $ region level in Panels A and B.  " ///
	"* significant at 10\%; ** at 5\%; *** at 1\%.  " ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable} " ///
	"\end{center}" ///
	"\end{table}")
	
cap log close

capture erase $data\tmp.dta
capture erase $data\tmp1.dta
capture erase $data\tmp2.dta
capture erase $data\tmp3.dta
capture erase $data\tmp4.dta
