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
***


* extract the *not* normalized third difference in the policy rate from the raw data
foreach var in US France Germany Italy Japan Sweden Switzerland "United Kingdom"{
	display "`var'"
	
	if "`var'"=="France" | "`var'"=="Italy" | "`var'"=="Sweden" | "`var'"=="Switzerland" {
		local range="R"
	}
	else{
		local range="Q"
	}
			
	import excel "rawdata/USMPF 2020 Financial Activity and Inflation Data.xlsx", clear sheet("`var' TRANSFORMED") cellrange(A6:`range'389)
	rename A date
	drop if date==""

	if "`var'"=="United Kingdom" local var = "uk"
	if "`var'"=="Switzerland" local var = "che"
	if "`var'"=="Germany" local var = "de"
	if "`var'"=="France" local var = "fra"
	if "`var'"=="Italy" local var = "it"
	if "`var'"=="Japan" local var = "jpn"
	if "`var'"=="Sweden" local var = "swe"
	if "`var'"=="US" local var = "us"

	gen ym=mofd(date(date+"01", "YMD"))
	format ym %tm
	drop date

	if "`var'"=="us"|"`var'"=="de"|"`var'"=="jpn"|"`var'"=="uk" {
		rename B `var'_equity_index
		rename C `var'_interbank_spread
		rename D `var'_yield_curve
		rename E `var'_credit_spread
		rename F `var'_loans_credit
		rename G `var'_fx_rate
		rename H `var'_equity_vol
		rename J `var'_inflation
		rename L `var'_activity_coin
		rename M `var'_activity_retail
		rename N `var'_activity_ip
		rename P `var'_policy_rate
		rename Q `var'_mbase_gdp
	}
	if "`var'"=="fra" | "`var'"=="it" | "`var'"=="swe" | "`var'"=="che" {
		rename B `var'_equity_index
		rename C `var'_interbank_spread
		rename D `var'_yield_curve
		rename E `var'_sovereign_spread
		rename F `var'_credit_spread
		rename G `var'_loans_credit
		rename H `var'_fx_rate
		rename I `var'_equity_vol
		rename K `var'_inflation
		rename M `var'_activity_coin
		rename N `var'_activity_retail
		rename O `var'_activity_ip
		rename Q `var'_policy_rate
		rename R `var'_mbase_gdp
	}

	keep ym `var'_*

	tempfile import`var'
	save "`import`var''"
}

use `importus', clear
foreach var in fra de it jpn swe che uk{
	merge 1:1 ym using `import`var'', nogen 
}
keep ym *_policy_rate
rename *_policy_rate *_policy_rate_notnorm

rename de_* deu_*

tempfile policyrate
save `policyrate'


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

*not normaised policy rate
merge 1:1 ym using `policyrate', nogen keep(1 3)



*start in 1989:01
drop in 1/9

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



*regressions for table A1:
matrix tablea1 = J(16,6,0)
matrix colnames tablea1 = dfci1 dfci2 both dfci1 dfci2 both
matrix rownames tablea1 = 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

forvalues n=1/6{
	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 indepvar = "inflation"
			local domesticvars = "L(4/9).pc1_dfci_`country'"
		}
		if `n'==2{
			local depvar = "activity_coin"
			local indepvar = "inflation"
			local domesticvars = "L(4/9).pc2_dfci_`country'"
		}
		if `n'==3{
			local depvar = "activity_coin"
			local indepvar = "inflation"
			local domesticvars = "L(4/9).pc1_dfci_`country' L(4/9).pc2_dfci_`country'"
		}
		if `n'==4{
			local depvar = "inflation"
			local indepvar = "activity_coin"
			local domesticvars = "L(4/9).pc1_dfci_`country'"
		}
		if `n'==5{
			local depvar = "inflation"
			local indepvar = "activity_coin"
			local domesticvars = "L(4/9).pc2_dfci_`country'"
		}
		if `n'==6{
			local depvar = "inflation"
			local indepvar = "activity_coin"
			local domesticvars = "L(4/9).pc1_dfci_`country' L(4/9).pc2_dfci_`country'"
		}
				
		regress `country'_`depvar' `country'_policy_rate_notnorm L(4/9).`country'_policy_rate_notnorm L(4/9).`country'_`depvar' `domesticvars' L(4/9).pc1_gfci L(4/9).`country'_`indepvar', robust
		
		test (L7.`country'_policy_rate_notnorm=0) (L8.`country'_policy_rate_notnorm=0) (L9.`country'_policy_rate_notnorm=0) (L4.`country'_policy_rate_notnorm=0) (L5.`country'_policy_rate_notnorm=0) (L6.`country'_policy_rate_notnorm=0)
		
		matrix tablea1[`m1',`n'] = `r(F)'
		matrix tablea1[`m2',`n'] = `r(p)'
	}
}

matrix list tablea1

esttab matrix(tablea1, fmt(%9.2f)) using "results/step4/4_regression_tablea1.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


