%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%By Marco Bernardini & Gert Peersman (June 2017)
%Figure 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clearvars;close all;clc
% close all
%% Load Data
% Private debt data (ratio of GDP)
[data,text]=xlsread('figMATLAB.xls','Fig1-2-8');
text=text(1,2:end);
time=(1919:0.25:2013.75)';
%Colors
pl=[153,0,153]./255;
dg=[0,102,0]./255;
do=[204,102,0]./255;
%% Figure 1
figure('visible','on')
[ax,h1,p2]=plotyy(time,data(:,strmatch('PRO',text,'exact')),time,[data(:,strmatch('PRY',text,'exact')),data(:,strmatch('PRY_trend',text,'exact'))],'bar','plot');
set(h1,'facecolor',[215 215 215]./255,'EdgeColor',[215 215 215]./255);hold(ax(1),'on');hold(ax(2),'on'),
set(p2,'linewidth',1.5,'color','r'),
p1=plot(ax(2),time,data(:,strmatch('PRY',text,'exact')),'-b','linewidth',1.5);
set(ax(1),'xlim',[time(1),time(end)],'YTick',[],'YTicklabel',[]),
set(ax(2),'xlim',[time(1),time(end)],'ylim',[20,180],'YTick',0:20:300,'YTicklabel',0:20:300,'YColor','k'),
box off,set(gcf, 'CurrentAxes', ax(1)) ,ylabel('Percentage points')
legend([p1;p2(1)],{'Private domestic nonfinancial debt-to-GDP','Smooth HP trend (\lambda = 1e6)'},'location','southoutside','orientation','horizontal','FontSize',8,'edgecolor','none');

set(findall(gcf,'type','text'),'FontSize',8) 
set(findall(gcf,'type','axes'),'FontSize',8)
set(gcf,'PaperUnits', 'inches','PaperPosition',[0,0,6,4]);
print(gcf,'fig1','-depsc')
