
clear
set more off

********************************************************************************
********************************************************************************
* Merge COVID-19 epidemics data, elections data and demographic data
********************************************************************************
********************************************************************************

use "$temp/departement_covid_19", clear

merge n:1 departement_code using "$temp/departement_turnout_2020"
drop if _merge == 2
drop _merge
renvars voters votes turnout, suffix("_2020")

merg n:1 departement_code using "$temp/departement_turnout_2014"
drop if _merge == 2
drop _merge
renvars voters votes turnout, suffix("_2014")

merge n:1 departement_code using "$temp/departement_demographics_2020_final"
drop if _merge == 2
drop _merge

merge n:1 departement_code using "$temp/departement_area"
drop if _merge == 2
drop _merge


* Sample selection and variables creation
********************************************************************************

* Keep metropolitan France only
drop if length(departement_code) == 3

* Compute population density
gen density = population/surf_km2

*Department identifier
egen id_dep = group(departement_code)

*Cumulated hospitalization per capita
gen nbre_hospit_corona_cum_pc = nbre_hospit_corona_cum/population*100000

* Save
********************************************************************************
compress
save "$temp/temp_final", replace


