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

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

**** REPLICATION OF TABLE B7 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. DESCRIPTIVES TABLE
*/

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

// Import survey data

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

keep if dep_inc==1

// Controls

replace male=. if sex==.

// Macros for sample

global outcomes "confiance_ecole confiance_justi confiance_polic confiance_armee confiance_parti vote_ERW_ever vote_P2002R1_ERW_post"
global controls_i "birthyr i.parents i.religion i.annee_fep#i.wave_enc"

// Labels

la var alsace 				"Alsace"
la var born_1908_1913 		"[0.3em] Born 1908-1913" 
la var p_g1_1908_1913 		"[0.3em] Born 1908-13 (Father)" 
la var p_g2_1908_1913 		"[0.3em] Born 1908-13 (G.-father)" 
la var perc_i_full		 	"\\ Conscription proxy (\%)"

la var annee_fep		"\\ Survey year"
la var birthyr 			"[0.3em] Year-of-birth"
la var alsace 			"[0.3em] Alsace"
la var male 			"[0.3em] Male"
la var p_g1_1908_1913 	"[0.3em] Born 1908-1913: Father"
la var p_g2_1908_1913 	"[0.3em] Born 1908-1913: Grandfather"

tab wave_enc, g(wave_)
rename wave_enc wave

la var wave_1		"\\ Survey: 2002 Wave 1"
la var wave_2		"[0.3em] \multicolumn{1}{l}{2002 Wave 2}"
la var wave_3		"[0.3em] \multicolumn{1}{l}{2002 Wave 3}"
la var wave_4		"[0.3em] \multicolumn{1}{l}{2007 Wave 1}"

// Get stats

estpost tabstat ///
	wave_* 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(French Electoral Panel 2002-2007: 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 ///
	perc_i_full ///
	, 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", append style(tex) type label ///
	unstack collabels(none) ///
	mlabels(, none) ///
	msign(--) //

estpost tabstat ///
	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 confiance_ecole 	"\\ Trust in: Schooling system"
la var confiance_justi 	"[0.3em] \multicolumn{1}{l}{Judicial system}"
la var confiance_polic 	"[0.3em] \multicolumn{1}{l}{Police}"
la var confiance_armee 	"[0.3em] \multicolumn{1}{l}{Army}"
la var confiance_parti 	"[0.3em] \multicolumn{1}{l}{Political parties}"
la var vote_ERW_ever 	"\\ Ever voted for the radical right"
la var vote_P2002R1_ERW_post 	"[0.3em] Voted for the radical right in 2002R1"

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

la var parents_1 			"\\ Parents nationality: One foreign"
la var parents_2 			"[0.3em] \multicolumn{1}{l}{Both parents foreign}"
la var parents_3		 	"[0.3em] \multicolumn{1}{l}{One grandparent foreign}"
la var parents_4 			"[0.3em] \multicolumn{1}{l}{None foreign}"
la var religion_1			"[0.3em] Religion: Roman Catholic" 
la var religion_2			"[0.3em] \multicolumn{1}{l}{Protestant}" 
la var religion_3			"[0.3em] \multicolumn{1}{l}{Muslim}" 
la var religion_4			"[0.3em] \multicolumn{1}{l}{Other}" 
la var religion_5			"[0.3em] \multicolumn{1}{l}{No religion}" 

// Macros

global outcomes "confiance_ecole confiance_justi confiance_polic confiance_armee confiance_parti vote_ERW_ever vote_P2002R1_ERW_post"
global controls_i "parents_1 parents_2 parents_3 parents_4 religion_1 religion_2 religion_3 religion_4 religion_5"

// 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 Table \ref{EEREV-D-21-00004_Table10}. " ///
	"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_FEP} for the construction of the other variables. " ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
