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

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

**** REPLICATION OF FIGURE B3 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. CORRELATION GRAPH - RELIGION
	2. CORRELATION GRAPH - LANGUAGE
*/

*******************************************
***** 1. CORRELATION GRAPH - RELIGION *****
*******************************************

// Import municipality data

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

drop if annee!=1969
drop if dep!=57 & dep!=67 & dep!=68

keep ct_1936_str ar_1936_str com church_cath church_prot church_jewi

g church_data=1*(church_cath!=. & church_prot!=. & church_jewi!=.)

// Collapse data

collapse (sum) church_cath church_prot (mean) church_data, by(ct_1936_str ar_1936_str)
drop if church_data!=1 // Full cantons
drop church_data

// Merge with aggregate data

merge m:1 ct_1936_str ar_1936_str using $data\EEREV-D-21-00004_Data_Canton1936.dta
drop if _merge==2 // no church data
drop _merge

// Generate variables

g church_data=(church_prot*100)/(church_prot+church_cath)
g census_data=(perc_prot_1936*100)/(perc_cath_1936+perc_prot_1936)

// Graph

pwcorr church_data census_data, sig o // Corr=0.9690

twoway ///
	(scatter church_data census_data) /// 	
	(lfit church_data census_data, lp(dash) lcolor(maroon)), /// 
	ytitle("Church data: Protestant churches (%)", margin(vsmall)) ylabel(0(30)60, angle(0) format(%5.0f)) yscale(r(-6 66)) ///
	xlabel(0(40)80, format(%5.0f)) xscale(r(-8 88)) /// 
	xtitle("INSEE (1956): Protestants 1936 (%)", margin(small)) ///
	legend(off) title("Religion", ring(0)) graphregion(color(white)) name(religion, replace) //

*******************************************
***** 2. CORRELATION GRAPH - LANGUAGE *****
*******************************************

// Import municipality data

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

drop if annee!=1969
drop if dep!=57 & dep!=67 & dep!=68

keep ct_1936_str ar_1936_str com p_french_name pop_1936

// Collapse data

collapse (mean) p_french_name [w=pop_1936], by(ct_1936_str ar_1936_str)

// Merge with aggregate data

merge m:1 ct_1936_str ar_1936_str using $data\EEREV-D-21-00004_Data_Canton1936.dta
drop _merge

// Graph

pwcorr perc_fran_1936 p_french_name, sig o // 0.8653

twoway ///
	(scatter p_french_name perc_fran_1936) /// 	
	(lfit p_french_name perc_fran_1936, lp(dash) lcolor(maroon) range(0 60)), ///
	ytitle("Birth data: French family name (%)", margin(vsmall)) ylabel(0(7)14, angle(0) format(%5.0f)) yscale(r(-1.4 15.4)) ///
	xlabel(0(30)60, format(%5.0f)) xscale(r(-6 66)) /// 
	xtitle("INSEE (1956): French-speaking only", margin(small)) ///
	legend(off) title("Language", ring(0)) graphregion(color(white)) name(language, replace) //	

graph combine religion language ///
	, c(2) graphregion(color(white)) imargin(vsmall) //ycommon
graph export "$results\\$program.png", replace width(7200) height(3000)

cap log close
