%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%By Marco Bernardini & Gert Peersman (June 2017)
%Figure 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clearvars;close all;clc
dg=[51,101,0]./255;
%%
[dataBP,textBP]=xlsread('figMATLAB.xls','Fig3_BP_data');
dataBP=dataBP(1:12,:);
[dataDN,textDN]=xlsread('figMATLAB.xls','Fig3_DN_data');
dataDN=dataDN(1:12,:);
time=dataBP(:,1);
zz=zeros(size(time));
%
figure('visible','on')
subplot(2,2,1) %Government spending
    %Main Low
    grpyat=[time,dataBP(:,strmatch('upsdA_gov_90',textBP));flipud(time),flipud(dataBP(:,strmatch('losdA_gov_90',textBP)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataBP(:,strmatch('bsdA_gov',textBP)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataBP(:,strmatch('bsdB_gov',textBP)),'b-^',time,dataBP(:,strmatch('upsdB_gov',textBP)),'b--',time,dataBP(:,strmatch('losdB_gov',textBP)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-1,6]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Government spending';''})
subplot(2,2,2) %Gross Domestic Product
    %Main Low
    grpyat=[time,dataBP(:,strmatch('upsdA_gdp_90',textBP));flipud(time),flipud(dataBP(:,strmatch('losdA_gdp_90',textBP)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataBP(:,strmatch('bsdA_gdp',textBP)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataBP(:,strmatch('bsdB_gdp',textBP)),'b-^',time,dataBP(:,strmatch('upsdB_gdp',textBP)),'b--',time,dataBP(:,strmatch('losdB_gdp',textBP)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-1,8]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'GDP';''})
subplot(2,2,3) %Consumption
    %Main Low
    grpyat=[time,dataBP(:,strmatch('upsdA_con_90',textBP));flipud(time),flipud(dataBP(:,strmatch('losdA_con_90',textBP)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataBP(:,strmatch('bsdA_con',textBP)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataBP(:,strmatch('bsdB_con',textBP)),'b-^',time,dataBP(:,strmatch('upsdB_con',textBP)),'b--',time,dataBP(:,strmatch('losdB_con',textBP)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-0.4,2]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Consumption';''})
subplot(2,2,4) %Investment
    %Main Low
    grpyat=[time,dataBP(:,strmatch('upsdA_inv_90',textBP));flipud(time),flipud(dataBP(:,strmatch('losdA_inv_90',textBP)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataBP(:,strmatch('bsdA_inv',textBP)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataBP(:,strmatch('bsdB_inv',textBP)),'b-^',time,dataBP(:,strmatch('upsdB_inv',textBP)),'b--',time,dataBP(:,strmatch('losdB_inv',textBP)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-1,1.4]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Investment';''})
set(findall(gcf,'type','text'),'FontSize',11) 
set(findall(gcf,'type','axes'),'FontSize',11)
%set(gcf,'PaperUnits', 'inches','PaperPosition',[0,0,8,4]);
print('fig3_BP','-depsc')
%
figure('visible','on')
subplot(2,2,1) %Government spending
    %Main Low
    grpyat=[time,dataDN(:,strmatch('upsdA_gov_90',textDN));flipud(time),flipud(dataDN(:,strmatch('losdA_gov_90',textDN)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataDN(:,strmatch('bsdA_gov',textDN)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataDN(:,strmatch('bsdB_gov',textDN)),'b-^',time,dataDN(:,strmatch('upsdB_gov',textDN)),'b--',time,dataDN(:,strmatch('losdB_gov',textDN)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-0.2,2]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Government spending';''})
subplot(2,2,2) %Gross Domestic Product
    %Main Low
    grpyat=[time,dataDN(:,strmatch('upsdA_gdp_90',textDN));flipud(time),flipud(dataDN(:,strmatch('losdA_gdp_90',textDN)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataDN(:,strmatch('bsdA_gdp',textDN)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataDN(:,strmatch('bsdB_gdp',textDN)),'b-^',time,dataDN(:,strmatch('upsdB_gdp',textDN)),'b--',time,dataDN(:,strmatch('losdB_gdp',textDN)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-0.2,2.2]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'GDP';''})
subplot(2,2,3) %Consumption
    %Main Low
    grpyat=[time,dataDN(:,strmatch('upsdA_con_90',textDN));flipud(time),flipud(dataDN(:,strmatch('losdA_con_90',textDN)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataDN(:,strmatch('bsdA_con',textDN)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataDN(:,strmatch('bsdB_con',textDN)),'b-^',time,dataDN(:,strmatch('upsdB_con',textDN)),'b--',time,dataDN(:,strmatch('losdB_con',textDN)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-0.1,0.3]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Consumption';''})
subplot(2,2,4) %Investment
    %Main Low
    grpyat=[time,dataDN(:,strmatch('upsdA_inv_90',textDN));flipud(time),flipud(dataDN(:,strmatch('losdA_inv_90',textDN)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataDN(:,strmatch('bsdA_inv',textDN)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataDN(:,strmatch('bsdB_inv',textDN)),'b-^',time,dataDN(:,strmatch('upsdB_inv',textDN)),'b--',time,dataDN(:,strmatch('losdB_inv',textDN)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-0.2,0.25]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Investment';''})
set(findall(gcf,'type','text'),'FontSize',11) 
set(findall(gcf,'type','axes'),'FontSize',11)
%set(gcf,'PaperUnits', 'inches','PaperPosition',[0,0,8,4]);
print('fig3_DN','-depsc')