%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%By Marco Bernardini & Gert Peersman (June 2017)
%Figure 7
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clearvars;close all;clc
% close all
dg=[102,255,102]./255;
%
[data,text]=xlsread('figMATLAB.xls','Fig1-2-8');
text=text(1,2:end);
time=(1919:0.25:2013.75)';
%states
pry=data(:,strmatch('PRO',text,'exact'));
del=data(:,strmatch('DELEV',text,'exact'));
gvy=data(:,strmatch('GVO',text,'exact'));
uns=data(:,strmatch('UNS',text,'exact'));
agv=data(:,strmatch('AGV',text,'exact'));
rec=data(:,strmatch('RECQ',text,'exact'));
zlb=data(:,strmatch('ZLB',text,'exact'));
smc=data(:,strmatch('SMC',text,'exact'));
bkc=data(:,strmatch('BC',text,'exact'));
%thresholds
%pry_v=data(:,strmatch('PRY',text,'exact'));
%ref_v=data(:,strmatch('PRY_trend',text,'exact'));
dev_v=100.*data(:,strmatch('PRY_cycle',text,'exact'))./data(:,strmatch('PRY_trend',text,'exact'));
uns_v=data(:,strmatch('UNEM',text,'exact'));
int_v=data(:,strmatch('NINT',text,'exact'));
%gvy_v=data(:,strmatch('GVY',text,'exact'));
%refg_v=data(:,strmatch('GVY_trend',text,'exact'));
devg_v=100.*data(:,strmatch('GVY_cycle',text,'exact'))./data(:,strmatch('GVY_trend',text,'exact'));
%%
figure('Name','Figure7','visible','on')
%
subplot(4,2,1)
[ax,h1,p2]=plotyy(time,bkc,time,pry,'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2,'linewidth',1,'color','k','linestyle','--'),
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[],'YColor','k'),
box off
title('(a) Banking crises')
%
subplot(4,2,2)
[ax,h1,p2]=plotyy(time,smc,time,pry,'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2,'linewidth',1,'color','k','linestyle','--'),
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[],'YColor','k'),
box off
title('(b) Stock market crashes')
%
subplot(4,2,3)
[ax,h1,p2]=plotyy(time,del,time,dev_v,'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2,'linewidth',2,'color','b'),
plot(ax(1),time,pry,'linewidth',1,'color','k','linestyle','--'),
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'ylim',[min(dev_v)-1.5*std(dev_v),max(dev_v)+1.5*std(dev_v)],'YTick',-100:20:100,'YTicklabel',-100:20:100,'YColor','k'),
box off
title('(c) Deleveraging periods (peak-to-trough)')
%
subplot(4,2,4)
[ax,h1,p2]=plotyy(time,uns,time,[zeros(size(dev_v))+6.5,uns_v],'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2(2),'linewidth',2,'color','b'),
set(p2(1),'linewidth',1,'color','r'),
plot(ax(1),time,pry,'linewidth',1,'color','k','linestyle','--'), 
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'ylim',[min(uns_v)-1.5*std(uns_v),max(uns_v)+1.5*std(uns_v)],'YTick',-100:5:100,'YTicklabel',-100:5:100,'YColor','k'),
box off
title('(d) Unemployment slack')
%
subplot(4,2,5)
[ax,h1,p2]=plotyy(time,agv,time,pry,'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2,'linewidth',1,'color','k','linestyle','--'),
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[],'YColor','k'),
box off
title('(e) AG Recessions')
%
subplot(4,2,6)
[ax,h1,p2]=plotyy(time,rec,time,pry,'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2,'linewidth',1,'color','k','linestyle','--'),
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[],'YColor','k'),
box off
title('(f) NBER Recessions')
%
subplot(4,2,7)
[ax,h1,p2]=plotyy(time,zlb,time,[zeros(size(int_v)),int_v],'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2(2),'linewidth',2,'color','b'),
set(p2(1),'linewidth',1,'color','r'),
plot(ax(1),time,pry,'linewidth',1,'color','k','linestyle','--'), 
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'ylim',[min(int_v)-1.5*std(int_v),max(int_v)+1.5*std(int_v)],'YTick',-100:5:100,'YTicklabel',-100:5:100,'YColor','k'),
box off
title('(g) Zero lower bound periods')
%
subplot(4,2,8)
[ax,h1,p2]=plotyy(time,gvy,time,[zeros(size(devg_v)),devg_v],'bar','plot');
set(h1,'facecolor',dg,'EdgeColor',dg);hold(ax(1),'on');hold(ax(2),'on'),
set(p2(2),'linewidth',2,'color','b'),
set(p2(1),'linewidth',1,'color','r'),
plot(ax(1),time,pry,'linewidth',1,'color','k','linestyle','--'), 
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'ylim',[min(devg_v)-1.5*std(devg_v),max(devg_v)+1.5*std(devg_v)],'YTick',-100:20:100,'YTicklabel',-100:20:100,'YColor','k'),
box off
title('(h) High government debt')

%%
fillPage(gcf);
print('fig7','-depsc')