%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%By Marco Bernardini & Gert Peersman (June 2017)
%Figure 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clearvars;close all;clc
dg=[51,101,0]./255;
%%
[dataNW,textNW]=xlsread('figMATLAB.xls','Fig5_BPnoWWIIKorea_data');
dataNW=dataNW(1:12,:);
[dataND,textND]=xlsread('figMATLAB.xls','Fig5_BP1952_data');
dataND=dataND(1:12,:);
time=dataNW(:,1);
zz=zeros(size(time));
%
figure('visible','on')
subplot(2,3,1) %Gross Domestic Product
    %Main Low
    grpyat=[time,dataNW(:,strmatch('upmulsdA_gdp_90',textNW));flipud(time),flipud(dataNW(:,strmatch('lomulsdA_gdp_90',textNW)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataNW(:,strmatch('bmulsdA_gdp',textNW)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataNW(:,strmatch('bmulsdB_gdp',textNW)),'b-^',time,dataNW(:,strmatch('upmulsdB_gdp',textNW)),'b--',time,dataNW(:,strmatch('lomulsdB_gdp',textNW)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-4.5,5.5]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'GDP multiplier';''})
subplot(2,3,2) %Consumption
    %Main Low
    grpyat=[time,dataNW(:,strmatch('upmulsdA_con_90',textNW));flipud(time),flipud(dataNW(:,strmatch('lomulsdA_con_90',textNW)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataNW(:,strmatch('bmulsdA_con',textNW)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataNW(:,strmatch('bmulsdB_con',textNW)),'b-^',time,dataNW(:,strmatch('upmulsdB_con',textNW)),'b--',time,dataNW(:,strmatch('lomulsdB_con',textNW)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-4.0,2.0]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Consumption multiplier';''})
subplot(2,3,3) %Investment
    %Main Low
    grpyat=[time,dataNW(:,strmatch('upmulsdA_inv_90',textNW));flipud(time),flipud(dataNW(:,strmatch('lomulsdA_inv_90',textNW)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataNW(:,strmatch('bmulsdA_inv',textNW)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataNW(:,strmatch('bmulsdB_inv',textNW)),'b-^',time,dataNW(:,strmatch('upmulsdB_inv',textNW)),'b--',time,dataNW(:,strmatch('lomulsdB_inv',textNW)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-3.5,1.5]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Investment multiplier';''})
subplot(2,3,4) %Gross Domestic Product
    %Difference
    grpyat=[time,dataNW(:,strmatch('upmulsdBA_gdp_90',textNW));flipud(time),flipud(dataNW(:,strmatch('lomulsdBA_gdp_90',textNW)))];
    patch(grpyat(:,1),grpyat(:,2),[204,255,204]./255,'edgecolor',[204,255,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataNW(:,strmatch('bmulsdBA_gdp',textNW)),'g','linewidth',2),hold on,
    axis tight,box off, ylim([-0.5,8.5]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
subplot(2,3,5) %Consumption
    %Difference
    grpyat=[time,dataNW(:,strmatch('upmulsdBA_con_90',textNW));flipud(time),flipud(dataNW(:,strmatch('lomulsdBA_con_90',textNW)))];
    patch(grpyat(:,1),grpyat(:,2),[204,255,204]./255,'edgecolor',[204,255,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataNW(:,strmatch('bmulsdBA_con',textNW)),'g','linewidth',2),hold on,
    axis tight,box off, ylim([-.5,4.5]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
subplot(2,3,6) %Investment
    %Difference
    grpyat=[time,dataNW(:,strmatch('upmulsdBA_inv_90',textNW));flipud(time),flipud(dataNW(:,strmatch('lomulsdBA_inv_90',textNW)))];
    patch(grpyat(:,1),grpyat(:,2),[204,255,204]./255,'edgecolor',[204,255,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataNW(:,strmatch('bmulsdBA_inv',textNW)),'g','linewidth',2),hold on,
    axis tight,box off, ylim([-0.5,4.5]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
set(findall(gcf,'type','text'),'FontSize',8) 
set(findall(gcf,'type','axes'),'FontSize',8)
set(gcf,'PaperUnits', 'inches','PaperPosition',[0,0,8,4]);
print(strcat(cd,'\fig5_BPNW'),'-depsc')
%
figure('visible','on')
subplot(2,3,1) %Gross Domestic Product
    %Main Low
    grpyat=[time,dataND(:,strmatch('upmulsdA_gdp_90',textND));flipud(time),flipud(dataND(:,strmatch('lomulsdA_gdp_90',textND)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataND(:,strmatch('bmulsdA_gdp',textND)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataND(:,strmatch('bmulsdB_gdp',textND)),'b-^',time,dataND(:,strmatch('upmulsdB_gdp',textND)),'b--',time,dataND(:,strmatch('lomulsdB_gdp',textND)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-1.5,2]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'GDP multiplier';''})
subplot(2,3,2) %Consumption
    %Main Low
    grpyat=[time,dataND(:,strmatch('upmulsdA_con_90',textND));flipud(time),flipud(dataND(:,strmatch('lomulsdA_con_90',textND)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataND(:,strmatch('bmulsdA_con',textND)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataND(:,strmatch('bmulsdB_con',textND)),'b-^',time,dataND(:,strmatch('upmulsdB_con',textND)),'b--',time,dataND(:,strmatch('lomulsdB_con',textND)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-0.6,0.6]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Consumption multiplier';''})
subplot(2,3,3) %Investment
    %Main Low
    grpyat=[time,dataND(:,strmatch('upmulsdA_inv_90',textND));flipud(time),flipud(dataND(:,strmatch('lomulsdA_inv_90',textND)))];
    patch(grpyat(:,1),grpyat(:,2),[255,204,204]./255,'edgecolor',[255,204,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataND(:,strmatch('bmulsdA_inv',textND)),'r-o','linewidth',2),hold on,
    %Main High
    plot(time,dataND(:,strmatch('bmulsdB_inv',textND)),'b-^',time,dataND(:,strmatch('upmulsdB_inv',textND)),'b--',time,dataND(:,strmatch('lomulsdB_inv',textND)),'b--','linewidth',2),hold on,...
    axis tight,box off, ylim([-1.5,1]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
    title({'Investment multiplier';''})
subplot(2,3,4) %Gross Domestic Product
    %Difference
    grpyat=[time,dataND(:,strmatch('upmulsdBA_gdp_90',textND));flipud(time),flipud(dataND(:,strmatch('lomulsdBA_gdp_90',textND)))];
    patch(grpyat(:,1),grpyat(:,2),[204,255,204]./255,'edgecolor',[204,255,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataND(:,strmatch('bmulsdBA_gdp',textND)),'g','linewidth',2),hold on,
    axis tight,box off, ylim([-1,3]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
subplot(2,3,5) %Consumption
    %Difference
    grpyat=[time,dataND(:,strmatch('upmulsdBA_con_90',textND));flipud(time),flipud(dataND(:,strmatch('lomulsdBA_con_90',textND)))];
    patch(grpyat(:,1),grpyat(:,2),[204,255,204]./255,'edgecolor',[204,255,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataND(:,strmatch('bmulsdBA_con',textND)),'g','linewidth',2),hold on,
    axis tight,box off, ylim([-.5,1]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
subplot(2,3,6) %Investment
    %Difference
    grpyat=[time,dataND(:,strmatch('upmulsdBA_inv_90',textND));flipud(time),flipud(dataND(:,strmatch('lomulsdBA_inv_90',textND)))];
    patch(grpyat(:,1),grpyat(:,2),[204,255,204]./255,'edgecolor',[204,255,204]./255);hold on,
    plot(time,zz,'k-'),hold on,
    plot(time,dataND(:,strmatch('bmulsdBA_inv',textND)),'g','linewidth',2),hold on,
    axis tight,box off, ylim([-0.25,1.75]),set(gca,'xtick',[0 3 7 11]','xticklabel',[' Q1';' Q4';' Q8';'Q12'])
set(findall(gcf,'type','text'),'FontSize',8) 
set(findall(gcf,'type','axes'),'FontSize',8)
set(gcf,'PaperUnits', 'inches','PaperPosition',[0,0,8,4]);
print(strcat(cd,'\fig5_BPND'),'-depsc')