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

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

**** REPLICATION OF TABLE B6 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. DESCRIPTIVES TABLE
*/

*********************************
***** 1. DESCRIPTIVES TABLE *****
*********************************

// Import inter-regional data

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

keep if dep_inc==1

// Controls

replace male=. if sex==.

// Macros for sample

global outcomes "confiance1 confiance2 confiance4 confiance5 confianceconfiance6 confiance9 confiance11 proximiteFN proximiteRPR proximitePS proximiteUDF proximiteECO proximiteCOM proximiteNA"
global controls_i "birthyr i.nationalite_pop i.religion i.anciennete annee"

// Labels

la var annee 			"\\ Survey year"
la var birthyr 			"[0.3em] Year-of-birth"
la var alsace 			"[0.3em] Alsace"
la var born_1908_1913 	"\\ Born 1908-1913"
la var born_1914_1927 	"[0.3em] Born 1914-1927"
la var male 			"[0.3em] Male"
la var p_s_1908_1913 	"[0.3em] Born 1908-1913: Husband"
la var p_g1_1908_1913 	"[0.3em] Born 1908-1913: Father"
la var p_g2_1908_1913 	"[0.3em] Born 1908-1913: Grandfather"

// Get stats

estpost tabstat ///
	annee birthyr male alsace ///
	, 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 0 0 0 0 0)) using ///
	"$results\\$program.tex", replace style(tex) type label ///
	unstack collabels(none) ///
	mlabels(, none) ///
	msign(--) ///
	title(Interregional Survey of Political Phenomena: Data description) ///
	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("")

estpost tabstat ///
	born_1908_1913 born_1914_1927 p_s_1908_1913 p_g1_1908_1913 p_g2_1908_1913 ///
	, 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 0 0 2 2 2)) using ///
	"$results\\$program.tex", append style(tex) type label ///
	unstack collabels(none) ///
	mlabels(, none) ///
	msign(--) //

// Labels

la var confiance1 	"\\ Trust in: Schooling system"
la var confiance2 	"[0.3em] \multicolumn{1}{l}{Judicial system}"
la var confiance4 	"[0.3em] \multicolumn{1}{l}{Police}"
la var confiance5 	"[0.3em] \multicolumn{1}{l}{Church}"
la var confiance6 	"[0.3em] \multicolumn{1}{l}{Army}"
la var confiance9 	"[0.3em] \multicolumn{1}{l}{Political parties}"
la var confiance11 	"[0.3em] \multicolumn{1}{l}{Elected politicians}"
la var proximiteCOM "\\ Party feeling closer to: Communist"
la var proximitePS 	"[0.3em] \multicolumn{1}{l}{Socialist}"
la var proximiteECO	"[0.3em] \multicolumn{1}{l}{Ecologist}"
la var proximiteUDF	"[0.3em] \multicolumn{1}{l}{Liberal}"
la var proximiteRPR	"[0.3em] \multicolumn{1}{l}{Conservative}"
la var proximiteFN	"[0.3em] \multicolumn{1}{l}{Radical right}"
la var proximiteNA	"[0.3em] \multicolumn{1}{l}{None}"

foreach var in nationalite_pop religion anciennete{
	tab `var', g(`var'_)
}

la var nationalite_pop_2 	"\\ Father nationality: French"
la var nationalite_pop_1 	"[0.3em] \multicolumn{1}{l}{Foreign}"
la var nationalite_pop_3 	"[0.3em] \multicolumn{1}{l}{Question not asked}"
la var religion_2			"[0.3em] Religion: Roman Catholic" 
la var religion_5			"[0.3em] \multicolumn{1}{l}{Protestant}" 
la var religion_4			"[0.3em] \multicolumn{1}{l}{Muslim}" 
la var religion_3			"[0.3em] \multicolumn{1}{l}{Jewish}" 
la var religion_1			"[0.3em] \multicolumn{1}{l}{Other}" 
la var religion_6			"[0.3em] \multicolumn{1}{l}{No religion}" 
la var religion_7			"[0.3em] \multicolumn{1}{l}{Question not asked}" 
la var anciennete_3			"[0.3em] Family in region: Since always"
la var anciennete_2			"[0.3em] \multicolumn{1}{l}{Since parents}" 
la var anciennete_1			"[0.3em] \multicolumn{1}{l}{I moved}" 
la var anciennete_4			"[0.3em] \multicolumn{1}{l}{Question not asked}" 

// Macros

global outcomes "confiance1 confiance2 confiance4 confiance5 confiance6 confiance9 confiance11 proximiteCOM proximitePS proximiteECO proximiteUDF proximiteRPR proximiteFN proximiteNA"
global controls_i "nationalite_pop_2 nationalite_pop_1 nationalite_pop_3 religion_2 religion_5 religion_4 religion_3 religion_1 religion_6 religion_7 anciennete_3 anciennete_2 anciennete_1 anciennete_4"

// Get stats

estpost tabstat ///
	$outcomes $controls_i ///
	, 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 0 0 0 0 0)) using ///
	"$results\\$program.tex", append style(tex) type label ///
	unstack collabels(none) ///
	mlabels(, none) ///
	msign(--) ///
	prehead("") ///
	posthead("") ///
	prefoot("\\") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" ///
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 	
	"Covariates used in Section \ref{CONCEPTUAL}. " ///
	"The unit of observation is an individual. " ///
	"See Online Appendix \ref{OA_BIRTH_D} for the construction of the probabilities. " ///
	"See Online Appendix \ref{OA_SURVEY_DATA} for the construction of the other variables. " ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
