clear all
set more off
net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o)

* Set directory path -- to where XLS and DO files are.
capture cd "C:\Documents and Settings\Favero\My Documents\My Dropbox\confidence\Economic Policy\replication\Robustness - Blanchard Leigh"
* capture cd "/Users/matteoparadisi/Dropbox/confidence/Economic Policy/replication/robustness/BL"

import excel "dat_imf&conf_database_1970-2014.xlsx", sheet("Panel") firstrow clear
rename Year year
rename Country country
keep year country IMF* imf*
drop if (year<2010|year>2013)
destring IMF* imf*, replace
sort country year

save recent_plans.dta, replace

import excel "GDP Model Errors.xlsx", sheet("stata") firstrow clear
egen idcountry=group(country)
reshape long err, i(idcountry) j(year)
sort country year
merge country year using "recent_plans.dta"

drop if _merge==2
drop _merge


gen imf_tax_impact=IMF_TAX_UT+IMF_TAX_att
gen imf_spnd_impact=IMF_SPND_UT+IMF_SPND_att
gen imf_tot_impact=imf_tax_impact+imf_spnd_impact
gen imf_tax_plan=IMF_TAX_UT+IMF_TAX_att+IMF_TAX_att1+IMF_TAX_att2+IMF_TAX_att3+IMF_TAX_att4+IMF_TAX_att5
gen imf_spnd_plan=IMF_SPND_UT+IMF_SPND_att+IMF_SPND_att1+IMF_SPND_att2+IMF_SPND_att3+IMF_SPND_att4+IMF_SPND_att5
gen imf_tot_plan=imf_tax_plan+imf_spnd_plan
gen imf_tot_ann=IMF_TAX_att1+IMF_TAX_att2+IMF_TAX_att3+IMF_TAX_att4+IMF_TAX_att5+IMF_SPND_att1+IMF_SPND_att2+IMF_SPND_att3+IMF_SPND_att4+IMF_SPND_att5


*Replication of Table 6
***********************************************************************
*ATTEMPT TO REPLICATE EXACTLY B&L
***********************************************************************
tsset id year
preserve
gen y=err+L.err
gen x=imf_tot_impact+L.imf_tot_impact
keep if year==2011
reg y x, r
outreg2 using BLresults.xls, replace
restore

***********************************************************************
*B&L EXPLOITING Y-O-Y DATA
***********************************************************************

*clustered SE (only a few number of groups!)
reg err imf_tot_impact, cluster(id)
outreg2 using BLresults.xls, append
xtreg err imf_tot_impact, fe cluster(id)
outreg2 using BLresults.xls, append

*separate announcement and impact
xtreg err imf_tot_impact imf_tot_ann, fe cluster(id)
outreg2 using BLresults.xls, append

***********************************************************************


*FURTHER CHECKS (not shown in Table 6)
***********************************************************************
*isolating TB and EB parts
*using components directly
reg err imf_tax_impact imf_spnd_impact, r
reg err imf_tax_plan imf_spnd_plan, r
xtreg err imf_tax_impact imf_spnd_impact, fe vce(robust)
xtreg err imf_tax_plan imf_spnd_plan, fe vce(robust)
xi: xtreg err imf_tax_impact imf_spnd_impact i.year, fe vce(robust)
xi: xtreg err imf_tax_plan imf_spnd_plan i.year, fe vce(robust)

*using dummy interactions
gen imf_imp_eb=imf_tot_impact*IMF_EB
gen imf_imp_tb=imf_tot_impact*IMF_TB
gen imf_plan_eb=imf_tot_plan*IMF_EB
gen imf_plan_tb=imf_tot_plan*IMF_TB

reg err  imf_imp_eb imf_imp_tb, r
reg err imf_plan_eb imf_plan_tb, r
xtreg err imf_imp_eb imf_imp_tb, fe vce(robust)
xtreg err imf_plan_eb imf_plan_tb, fe vce(robust)
xi: xtreg err imf_imp_eb imf_imp_tb i.year, fe vce(robust)
xi: xtreg err imf_plan_eb imf_plan_tb i.year, fe vce(robust)

*using interactions
*EB interactions
reg err  imf_imp_eb IMF_EB imf_tot_impact, r
lincom imf_imp_eb+imf_tot_impact
reg err  imf_plan_eb IMF_EB imf_tot_plan, r
lincom imf_plan_eb+imf_tot_plan
xtreg err imf_imp_eb IMF_EB imf_tot_impact, fe vce(robust)
lincom imf_imp_eb+imf_tot_impact
xtreg err imf_plan_eb IMF_EB imf_tot_plan, fe vce(robust)
lincom imf_plan_eb+imf_tot_plan
xi: xtreg err imf_imp_eb IMF_EB imf_tot_impact i.year, fe vce(robust)
lincom imf_imp_eb+imf_tot_impact
xi: xtreg err imf_plan_eb IMF_EB imf_tot_plan i.year, fe vce(robust)
lincom imf_plan_eb+imf_tot_plan

