********************Change directory************************************

global input "\\input"
global do "\\do"
global inter "\\inter"
global output "\\out"


********************Start of clean and build****************************

//data clean
//regression program
cap prog drop autoreg
prog def autoreg

xtset id wave
xtreg w_c19perBeh01_Harmonized sft_pca $x if m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca $x if m2!=2, vce(cluster country)
xtreg w_c19perBeh03_Harmonized sft_pca $x if m2!=2, vce(cluster country)
xtreg w_Vaccine sft_pca $x if m2!=2, vce(cluster country)
xtreg w_c19RCA01 sft_pca $x if m2!=1, vce(cluster country)

xtreg w_c19perBeh01_Harmonized sft_pca_wght $x if m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca_wght $x if m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca_wght $x if m2!=2, vce(cluster country)
xtreg w_Vaccine sft_pca_wght $x if m2!=2, vce(cluster country)
xtreg w_c19RCA01 sft_pca_wght $x if m2!=1, vce(cluster country)

xtreg w_c19perBeh01_Harmonized sft_pca $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_Vaccine sft_pca $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca $x if age<=5&m2!=1, vce(cluster country) 

xtreg w_c19perBeh01_Harmonized sft_pca_wght $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca_wght $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca_wght $x if age<=5&m2!=2, vce(cluster country)
xtreg w_Vaccine sft_pca_wght $x if age<=5&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca_wght $x if age<=5&m2!=1, vce(cluster country)
 
xtreg w_c19perBeh01_Harmonized sft_pca $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_Vaccine sft_pca $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca $x if age<=2&m2!=1, vce(cluster country) 

xtreg w_c19perBeh01_Harmonized sft_pca_wght $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca_wght $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca_wght $x if age<=2&m2!=2, vce(cluster country)
xtreg w_Vaccine sft_pca_wght $x if age<=2&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca_wght $x if age<=2&m2!=1, vce(cluster country)

xtreg w_c19perBeh01_Harmonized sft_pca $x if coronaClose==0&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca $x if coronaClose==0&m2!=2,vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca $x if coronaClose==0&m2!=2, vce(cluster country) 
xtreg w_Vaccine sft_pca $x if coronaClose==0&m2!=2,vce(cluster country) 
xtreg w_c19RCA01 sft_pca $x if coronaClose==0&m2!=1, vce(cluster country) 

xtreg w_c19perBeh01_Harmonized sft_pca_wght $x if coronaClose==0&m2!=2,vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca_wght $x if coronaClose==0&m2!=2,vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca_wght $x if coronaClose==0&m2!=2,vce(cluster country)
xtreg w_Vaccine sft_pca_wght $x if coronaClose==0&m2!=2,vce(cluster country) 
xtreg w_c19RCA01 sft_pca_wght $x if coronaClose==0&m2!=1, vce(cluster country)

xtreg w_c19perBeh01_Harmonized sft_pca $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_Vaccine sft_pca $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca $x if coronaClose==0&age<=5&m2!=1, vce(cluster country) 

xtreg w_c19perBeh01_Harmonized sft_pca_wght $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca_wght $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca_wght $x if coronaClose==0&age<=5&m2!=2, vce(cluster country)
xtreg w_Vaccine sft_pca_wght $x if coronaClose==0&age<=5&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca_wght $x if coronaClose==0&age<=5&m2!=1, vce(cluster country)

xtreg w_c19perBeh01_Harmonized sft_pca $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_Vaccine sft_pca $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca $x if coronaClose==0&age<=2&m2!=1, vce(cluster country) 

xtreg w_c19perBeh01_Harmonized sft_pca_wght $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh02_Harmonized sft_pca_wght $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_c19perBeh03_Harmonized sft_pca_wght $x if coronaClose==0&age<=2&m2!=2, vce(cluster country)
xtreg w_Vaccine sft_pca_wght $x if coronaClose==0&age<=2&m2!=2, vce(cluster country) 
xtreg w_c19RCA01 sft_pca_wght $x if coronaClose==0&age<=2&m2!=1, vce(cluster country)

end


//program for clean
cap prog drop autoclean
prog def autoclean
sort ResponseId
cap drop id
gen id=_n
merge n:1 CountryName using "${inter}/OOPGDP", keepusing(oops_che) gen(_merge1)
drop if _merge1==2
replace COUNTRYOut_of_pocket2019=oops_che if COUNTRYOut_of_pocket2019==.
replace COUNTRYOut_of_pocket2019=38.7 if CountryName=="Palestine" 
replace COUNTRYOut_of_pocket2019=31 if CountryName=="Taiwan" 

cap drop education
gen education=1 if edu>=4
replace education=0 if edu<4

rename coronaClose_1 w0_coronaClose_1 
rename coronaClose_2 w0_coronaClose_2
rename employstatus_* w0_employstatus_*
rename c19perBeh0* w0_c19perBeh0*
rename PFS01 w0_PFS01

order id w0_c19perBeh01_Harmonized w0_c19perBeh02_Harmonized  w0_c19perBeh03_Harmonized 
cap drop unemployment
gen unemployment=.
forvalues i =1(1)10{  
replace unemployment=0 if w0_employstatus_`i'==1|w1_employstatus_`i'==1|w2_employstatus_`i'==1|w3_employstatus_`i'==1|w4_employstatus_`i'==1|w5_employstatus_`i'==1|w7_employstatus_`i'==1
}

forvalues i =1(1)14{  
replace unemployment=0 if w11_employstatus_`i'==1|w12_employstatus_`i'==1|w13_employstatus_`i'==1|w14_employstatus_`i'==1|w15_employstatus_`i'==1|w16_employstatus_`i'==1
}

forvalues i =11(1)14{  
replace unemployment=0 if w4_employstatus_`i'==1|w5_employstatus_`i'==1|w7_employstatus_`i'==1|w14_employstatus_`i'==1
}

forvalues i =11(1)13{  
replace unemployment=0 if w1_employstatus_`i'==1|w2_employstatus_`i'==1|w3_employstatus_`i'==1
}

replace unemployment=1 if w0_employstatus_4==1|w1_employstatus_4==1|w2_employstatus_4==1|w3_employstatus_4==1|w4_employstatus_4==1|w5_employstatus_4==1|w7_employstatus_4==1|w11_employstatus_4==1|w12_employstatus_4==1|w13_employstatus_4==1|w14_employstatus_4==1|w15_employstatus_4==1|w16_employstatus_4==1|w1_employstatus_11==1|w2_employstatus_11==1|w3_employstatus_11==1|w4_employstatus_11==1|w5_employstatus_11==1|w7_employstatus_11==1|w11_employstatus_11==1|w12_employstatus_11==1|w13_employstatus_11==1|w14_employstatus_11==1|w15_employstatus_11==1|w16_employstatus_11==1|w1_employstatus_12==1|w2_employstatus_12==1|w3_employstatus_12==1|w4_employstatus_12==1|w5_employstatus_12==1|w7_employstatus_12==1|w11_employstatus_12==1|w12_employstatus_12==1|w13_employstatus_12==1|w14_employstatus_12==1|w15_employstatus_12==1|w16_employstatus_12==1

rename c19RCA01 w0_c19RCA01
rename PLRAC19 w0_PLRAC19
tolong w*_coronaClose_1 w*_coronaClose_2  w*_c19perBeh01_Harmonized  w*_c19perBeh02_Harmonized w*_c19perBeh03_Harmonized w*_PFS01 w*_Vaccine w*_c19RCA01 w*_PLRAC19,i(id)

rename _j wave

label define wave 0 "March 19, 2020" 1"March 27, 2020" 2"April 11, 2020" 3"April 18, 2020" 4"April 25, 2020" 5"May 2, 2020" 6"May 9, 2020"  7"May 16, 2020" 8"May 23, 2020"  9"May 30, 2020"  10"June 6, 2020" 11"June 13, 2020" 12"July 13, 2020" 13"August 13, 2020" 14"September 13, 2020" 15"October 13, 2020" 16"November 13, 2020" 17 "December 13, 2020"18 "January 13, 2021" 19 "February 13, 2021" 20 "March 13, 2021" 21 "April 13, 2021" 22 "July 13, 2021"
label value wave wave
cap drop wave1
gen wave1=""
replace wave1="March 19, 2020" if wave==0
replace wave1="March 27, 2020" if wave==1
replace wave1="April 11, 2020" if wave==2
replace wave1="April 18, 2020" if wave==3
replace wave1="April 25, 2020" if wave==4
replace wave1="May 2, 2020" if wave==5
replace wave1="May 9, 2020" if wave==6
replace wave1="May 16, 2020" if wave==7
replace wave1="May 23, 2020" if wave==8
replace wave1="May 30, 2020" if wave==9
replace wave1="June 6, 2020" if wave==10
replace wave1="June 13, 2020" if wave==11
replace wave1="July 13, 2020" if wave==12
replace wave1="August 13, 2020" if wave==13
replace wave1="September 13, 2020" if wave==14
replace wave1="October 13, 2020" if wave==15
replace wave1="November 13, 2020" if wave==16
replace wave1="December 13, 2020" if wave==17
replace wave1="January 13, 2021" if wave==18
replace wave1="February 13, 2021" if wave==19
replace wave1="March 13, 2021" if wave==20
replace wave1="April 13, 2021" if wave==21
replace wave1="July 13, 2021" if wave==22
cap drop edate
gen edate=date(wave1,"MDY") 
format edate %dM_d,_CY

end

//program for standardize
cap prog drop std
prog def std
foreach k in w_c19perBeh01_Harmonized w_c19perBeh02_Harmonized w_c19perBeh03_Harmonized  w_Vaccine w_c19RCA01 lnCOUNTRYGDPpc COUNTRYOut_of_pocket2019 cases_population_7day stringency_index people_vaccinated_per_hundred sft_pca sft_pca_wght w_PFS {
	cap drop std`k'
	egen std`k'=std(`k')
	replace `k'=std`k'
}
end

//add control variable
do "${do}/do_control"

//generated all sft needed
do "${do}/do_sft"

//data clean for main regression
do "${do}/do_clean_main_regression"


********************End of clean and build****************************

//Figure 1 & Figure S6
do "${do}/do_figure1_figureS6"
*Manuscript Figure 2
do "${do}/do_figure2"
*Manuscript Figure 3
do "${do}/do_figure3"
*Manuscript Figure 4
do "${do}/do_figure4"

*Table S1
do "${do}/do_table_S1"
*Table S2
do "${do}/do_table_S2"
*Table S3
do "${do}/do_table_S3"
*Table S4
do "${do}/do_table_S4"
*Table S5
do "${do}/do_table_S5"
*Table S6
do "${do}/do_table_S6"
*Table S7 
do "${do}/do_table_S7"

*Table S8
do "${do}/do_table_S8"
*Table S9
do "${do}/do_table_S9"
*Table S10&Table S11
do "${do}/do_table_S10_S11"
*Table S12
do "${do}/do_table_S12"

*Figure S1 & Figure S2
do "${do}/do_figure_S1_S2"

* Figure S3
do "${do}/do_figure_S3"

* Figure S4
do "${do}/do_Table_S4"

* Figure S5
do "${do}/do_figure_S5"

