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

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

**** REPLICATION OF TABLE B4 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. DESCRIPTIVES TABLE
*/

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

// Improt Microcensus data

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

global controls "birthyr index male eligible index_eligible frenchnat germannat othernat catholic protestant other speakfrench hhold_head hhold_size"

// Full sample

estpost tabstat ///
	$controls ///
	, 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 b1 = obs, mean, sd, min, p5, p50, p95, max
matrix list b1

// Label variables

la var birthyr "Year-of-birth"
la var male "[0.3em] Male"
la var index_male"[0.3em] \multicolumn{1}{l}{of whom in the \textit{Index}}"
la var eligible "[0.3em] Eligible for Wehrmacht"
la var index_eligible"[0.3em] \multicolumn{1}{l}{of whom in the \textit{Index}}"
la var frenchnat "[0.3em] Nationality: French"
la var germannat "[0.3em] \multicolumn{1}{l}{German}"
la var othernat "[0.3em] \multicolumn{1}{l}{Other}"
la var catholic "[0.3em] Religion: Roman catholic"
la var protestant "[0.3em] \multicolumn{1}{l}{Protestant}"
la var other "[0.3em] \multicolumn{1}{l}{Other}"
la var speakfrench "[0.3em] French speaking"
la var hhold_head "[0.3em] Household head"
la var hhold_size "[0.3em] Household size"
la var index "[0.3em] Appears in the \textit{Index}"

// Table

estout matrix(b1, 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(1936 Population census: Data description) ///
	prehead("\begin{table}[t!]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{scriptsize}" ///
	"\caption{@title}\label{$program}" ///
	"\label{$table}"  /// 
	"\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("\hline" "\hline" ///
	"\end{tabular*}" ///
	"\end{scriptsize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" ///
	"Data comes from the 1936 population census (\textit{Listes nominatives}). " ///
	"Individual-level data. " ///
	"All variables are binary with the exception of \textit{Year-of-birth} and \textit{Household size}. " ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
