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 first difference in the policy rate from the raw data
foreach var in "US Raw Data" France Germany Italy Japan Sweden Switzerland "United Kingdom"{
	display "`var'"
	
	if "`var'"=="France" | "`var'"=="Italy" | "`var'"=="Sweden" | "`var'"=="Switzerland" {
		local range="R"
	}
	else if "`var'"=="Germany" | "`var'"=="Japan" | "`var'"=="United Kingdom"{
		local range="Q"
	}
	else{
		local range="P"
	}
			
	import excel "rawdata/USMPF 2020 Financial Activity and Inflation Data.xlsx", clear sheet("`var'") 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 Raw Data" local var = "us"

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

	rename `range' `var'_policy_rate
	
	gen `var'_policy_rate_1 = `var'_policy_rate - `var'_policy_rate[_n-1]
	
	keep ym `var'_policy_rate_1

	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_1
rename *_policy_rate_1 *_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:07
drop in 1/15



*regressions for table A2
forvalues n=1/2{ //loop over domestic pc1 and pc2

	eststo clear
	foreach country in us fra deu it jpn swe che uk{
		eststo: regress pc`n'_dfci_`country' L(1).pc`n'_dfci_`country' pc1_gfci L(0/6).`country'_policy_rate_notnorm if ym<tm(2007m7), robust 

		*linear combination of coefficients
		lincom L0.`country'_policy_rate_notnorm + L1.`country'_policy_rate_notnorm + L2.`country'_policy_rate_notnorm + L3.`country'_policy_rate_notnorm + L4.`country'_policy_rate_notnorm + L5.`country'_policy_rate_notnorm + L6.`country'_policy_rate_notnorm
		estadd scalar policy_rate_b = `r(estimate)'
		estadd scalar policy_rate_t = `r(t)'

		lincom L1.pc`n'_dfci_`country'
		estadd scalar dfci_b = `r(estimate)'
		estadd scalar dfci_t = `r(t)'

		lincom pc1_gfci
		estadd scalar gfci_b = `r(estimate)'
		estadd scalar gfci_t = `r(t)'

	}
	esttab using "results/step4/4_regression_tablea2_pc`n'.csv", stats(dfci_b dfci_t gfci_b gfci_t policy_rate_b policy_rate_t N r2 , fmt(%9.2f) layout(@ `"(@)"' @ `"(@)"' @ `"(@)"' @ @)) drop(_cons *_policy_rate_notnorm *pc`n'_dfci* pc1_gfci) nostar replace
}


