function [title_boom] = all_boom_bust_country( num_boom, num_bust, boom_matrix, bust_matrix, indext_values_boom, boom_values, indext_values_bust, bust_values )


% PURPOSE: PRODUCE AND SAVE IN PDF FIGURES FOR BOOM/BUST EPISODES BY COUNTRY.
% 
% INPUT:
%     - num_boom: NUMBER OF BOOM IDENTIFIED
%     - num_bust: NUMBER OF BUST IDENTIFIED
%     - indext_values_boom: MATRIX WITH THE VALUES OF THE INDEXES IN BOOM EPISODES
%     - boom_values: MATRIX WITH THE VALUES OF OUTPUT GAP IN BOOM EPISODES
%     - indext_values_bust: MATRIX WITH THE VALUES OF TEH INDEXES IN THE BUST EPISODES
%     - bust_values: MATRIX WITH THE VALUES OF OUTPUT GAP IN THE BUST EPISODES


%Recall variable defined in the main script
global num_c schindler_years Countries

close all

x=[-2 -1 0 1 2];
label_x=[-2 -1 0 +1 +2];
label_y = [-0.5 0 0.5];

%Identify year and countries of the boom episodes
counter_years_sample=[1:1:schindler_years]';
years_sample=[1995:1:2011]';
years_id_matrix=[counter_years_sample years_sample];
counter_country_sample=[1:1:num_c]';

for i=1:num_boom
    for j=1:schindler_years
        if years_id_matrix(j,1)==boom_matrix(i,2)
            years_identifier_boom(i,1)=years_id_matrix(j,2);
        end
    end
end

for i=1:num_boom
    for j=1:num_c
        if counter_country_sample(j,1)==boom_matrix(i,1)
            country_identifier_boom(i,1)=Countries(j,1);
        end
    end
end

for i=1:num_boom
    virgola_boom(i,1)={','};
end

years_identifier_boom1=num2str(years_identifier_boom);
title_boom=strcat(country_identifier_boom, virgola_boom, years_identifier_boom1);

%BOOM
figure(1)
for i=1:15
    subplot(5,3,i)
    [haxes,hline1,hline2] = plotyy(indext_values_boom(i,2:end,2), 'b-+', 100*boom_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_boom(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_boom(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.a. Boom Episodes and Capital Controls: All Episodes','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(1), 'FigureA5a','-dpdf');

figure(2)
for i=16:30
    subplot(5,3,i-15)
    [haxes,hline1,hline2] = plotyy(indext_values_boom(i,2:end,2), 'b-+', 100*boom_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_boom(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_boom(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.a. Boom Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(2), 'FigureA5b','-dpdf');

figure(3)
for i=31:45
    subplot(5,3,i-30)
    [haxes,hline1,hline2] = plotyy(indext_values_boom(i,2:end,2), 'b-+', 100*boom_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_boom(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_boom(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.a. Boom Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(3), 'FigureA5c','-dpdf');

figure(4)
for i=46:60
    subplot(5,3,i-45)
    [haxes,hline1,hline2] = plotyy(indext_values_boom(i,2:end,2), 'b-+', 100*boom_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_boom(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_boom(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.a. Boom Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(4), 'FigureA5d','-dpdf');

figure(5)
for i=61:75
    subplot(5,3,i-60)
    [haxes,hline1,hline2] = plotyy(indext_values_boom(i,2:end,2), 'b-+', 100*boom_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_boom(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_boom(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.a. Boom Episodes and Capital Controls: All Episodes  (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(5), 'FigureA5e','-dpdf');

figure(6)
for i=76:num_boom
    subplot(5,3,i-75)
    [haxes,hline1,hline2] = plotyy(indext_values_boom(i,2:end,2), 'b-+', 100*boom_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_boom(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_boom(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.a. Boom Episodes and Capital Controls: All Episodes  (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(6), 'FigureA5f','-dpdf');

for i=1:num_bust
    for j=1:schindler_years
        if years_id_matrix(j,1)==bust_matrix(i,2)
            years_identifier_bust(i,1)=years_id_matrix(j,2);
        end
    end
end
 
for i=1:num_bust
    for j=1:num_c
        if counter_country_sample(j,1)==bust_matrix(i,1)
            country_identifier_bust(i,1)=Countries(j,1);
        end
    end
end
 
for i=1:num_bust
    virgola_bust(i,1)={','};
end
 
years_identifier_bust1=num2str(years_identifier_bust);
title_bust=strcat(country_identifier_bust, virgola_bust, years_identifier_bust1);

%BUST
figure(7)
for i=1:15
    subplot(5,3,i)
    [haxes,hline1,hline2] = plotyy(indext_values_bust(i,2:end,2), 'b-+', 100*bust_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_bust(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_bust(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.b. Bust Episodes and Capital Controls: All Episodes ','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(7), 'FigureA5g','-dpdf');

figure(8)
for i=16:30
    subplot(5,3,i-15)
    [haxes,hline1,hline2] = plotyy(indext_values_bust(i,2:end,2), 'b-+', 100*bust_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_bust(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_bust(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.b. Bust Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(8), 'FigureA5h','-dpdf');

figure(9)
for i=31:45
    subplot(5,3,i-30)
    [haxes,hline1,hline2] = plotyy(indext_values_bust(i,2:end,2), 'b-+', 100*bust_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_bust(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_bust(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.b. Bust Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(9), 'FigureA5i','-dpdf');

figure(10)
for i=46:60
    subplot(5,3,i-45)
    [haxes,hline1,hline2] = plotyy(indext_values_bust(i,2:end,2), 'b-+', 100*bust_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_bust(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_bust(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.b. Bust Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(10), 'FigureA5l','-dpdf');

figure(11)
for i=61:75
    subplot(5,3,i-60)
    [haxes,hline1,hline2] = plotyy(indext_values_bust(i,2:end,2), 'b-+', 100*bust_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_bust(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_bust(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.b. Bust Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print( figure(11), 'FigureA5m','-dpdf');

figure(12)
for i=76:num_bust
    subplot(5,3,i-75)
    [haxes,hline1,hline2] = plotyy(indext_values_bust(i,2:end,2), 'b-+', 100*bust_values(i,2:end) ,'r-*','plot');
    set(haxes, 'xTickLabel','')
    set(gca, 'XTick', 1:5, 'XTickLabel', label_x,'FontSize',10);
    xlabel('Years');
    set(haxes(1), 'yTickLabel','')
    set(haxes(1), 'yLim',[-0.5 0.5])
    set(haxes(1),'YTick',[-0.5 0 0.5], 'YTickLabel', label_y,'FontSize',10);
    t=title(title_bust(i,1),'FontWeight','bold');
    set(t,'FontSize',10);
    hold on
    set(haxes(1),'Nextplot','add');
    hline3=plot(indext_values_bust(i,2:end,3),'k-o');
    box off
    hold off
end
legend1 = legend([hline2 hline1 hline3],'Average Output Gap (rhs)', 'Inflow Index(lhs)', 'Outflow Index(lhs)');
set(legend1,'Orientation','horizontal','Position',[0.3375 0.0365942028985508 0.33359375 0.0195652173913043],'FontSize',6,'Color',[1 1 1],'Box','off');
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0.1 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure A.5.b. Bust Episodes and Capital Controls: All Episodes (Cont.)','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center')%,'VerticalAlignment', 'top'

%print(figure(12), 'FigureA5n','-dpdf');


end

