clear all

*** This is part of the replication files for 
* Cecchetti, Feroli, Kashyap, Mann and Schoenholtz (September 2020)
* 
*
* Julien Weber (julien.weber@chicagobooth.edu) 2020-09-14
***


*cleaned indices, nmp and activities
use "results/cleandata/data_with_conditions_and_nmp.dta", clear


*start in 1989:01
drop in 1/9

*end in 2019:04
drop in -8/L



*regressions for table A3
matrix tablea3 = J(16,8,0)
matrix colnames tablea3 = dfci1 dfci2 both1 both2 dfci1 dfci2 both1 both2
matrix rownames tablea3 = us_b us_t fra_b fra_t deu_b deu_t it_b it_t jpn_b jpn_t swe_b swe_t che_b che_t uk_b uk_t

forvalues n=1/8{
	local m1=-1
	local m2=0
	
	foreach country in us fra deu it jpn swe che uk{
		local m1=`m1'+2
		local m2=`m2'+2
		if `n'==1{
			local depvar = "activity_coin"
			local domesticvars = "L(4/9).pc1_dfci_`country'"
			local pc = 1
		}
		if `n'==2{
			local depvar = "activity_coin"
			local domesticvars = "L(4/9).pc2_dfci_`country'"
			local pc = 2
		}
		if `n'==3|`n'==4{
			local depvar = "activity_coin"
			local domesticvars = "L(4/9).pc1_dfci_`country' L(4/9).pc2_dfci_`country'"
			local pc = `n'-2
		}
		if `n'==5{
			local depvar = "inflation"
			local domesticvars = "L(4/9).pc1_dfci_`country'"
			local pc = 1
		}
		if `n'==6{
			local depvar = "inflation"
			local domesticvars = "L(4/9).pc2_dfci_`country'"
			local pc = 2
		}
		if `n'==7|`n'==8{
			local depvar = "inflation"
			local domesticvars = "L(4/9).pc1_dfci_`country' L(4/9).pc2_dfci_`country'"
			local pc = `n'-6
		}
				
		regress `country'_`depvar' L(4/9).`country'_`depvar' `domesticvars' L(4/9).pc1_gfci , robust
		
		*linear combination of coefficients
		lincom L7.pc`pc'_dfci_`country' + L8.pc`pc'_dfci_`country' + L9.pc`pc'_dfci_`country' + L4.pc`pc'_dfci_`country' + L5.pc`pc'_dfci_`country' + L6.pc`pc'_dfci_`country'
		
		matrix tablea3[`m1',`n'] = `r(estimate)'
		matrix tablea3[`m2',`n'] = `r(t)'
	}
}

esttab matrix(tablea3, fmt(%9.2f)) using "results/step4/4_regression_tablea3.csv", cells(us_F us_p fra_F fra_p deu_F deu_p it_F it_p jpn_F jpn_p swe_F swe_p che_F che_p uk_F uk_p, layout(@ `"(@)"' @ `"(@)"' @ `"(@)"' @ `"(@)"' @ `"(@)"' @ `"(@)"' @ `"(@)"' @ `"(@)"')) replace


