function [num_regime_boom, num_regime_bust, boom_bust_indicator, xt_average_matrix_boom, xt_average_matrix_bust, overall_average_matrix_boom, overall_average_matrix_bust, overall_interval_matrix_boom, overall_interval_matrix_bust] = exchange_regime_exercise( num_boom, num_bust, boom_matrix, bust_matrix, aggregate_xt, aggregate_ex_regime, aggregate_overall_indext )


% PURPOSE: IDENTIFY BOOM/BUST EPISODES IN DIFFERENT EXCHANGE RATE REGIMES, 
% CREATE THE MATRIX CONTAINING ALL EPISODES AND CALCULATE THE AVERAGES AND THE CONFIDENCE INTERVALS
% 
% INPUT:
%     -num_boom:NUMBER OF BOOM EPISODES
%     -num_bust:NUMBER OF BUST EPISODES
%     -boom_matrix: BOOM EPISODES MATRIX
%     -bust_matrix: BUST EPISODES MATRIX
%     -aggregate_xt: AGGREGATED OUTPUT GAP
%     -aggregate_ex_regimer: INDICATOR FOR EXCHNAGE RATE REGIME FOR COUNTRY
%     -aggregate_overall_indext: AGGREGATED OVERALL SCHINDLER INDEX
% 
% OUTPUT
%     -num_regime_boom:NUMBER OF BOOM EPISODES IN EACH EXCHANGE RATE REGIME
%     -num_regime_bust:NUMBER OF BUST EPISODES IN EACH EXCHANGE RATE REGIME
%     -boom_bust_indicator: MATRIX WITH ALL BOOM/BUST EPISODES
%     -xt_average_matrix_boom: AVERAGE OUTPUT GAP IN BOOM EPISODES
%     -xt_average_matrix_bust: AVERAGE OUTPUT GAP IN BUST EPISODES
%     -overall_average_matrix_boom: AVERAGE OVERALL INDEX IN BOOM EPISODES
%     -overall_average_matrix_bust: AVERAGE OVERALL INDEX IN BUST EPISODES
%     -overall_interval_matrix_boom: OVERALL INDEX CONFIDENCE INTERVAL IN BOOM EPISODES
%     -overall_interval_matrix_bust: OVERALL INDEX CONFIDENCE INTERVAL IN BUST EPISODES

%Recall variable defined in the main script
global num_c schindler_years

    num_column=5;
     
    %Counter for the years of the index
    schindler_years_list=[1:1:17]';

    %Create vector of years for all countries
    vector_years=repmat(schindler_years_list, [num_c 1]);

    %Create vector for country number identifier
    for i=1:num_c
        for j=1:schindler_years
            vector_country(j+schindler_years*(i-1),1)=i;
        end
    end

    %Create zeros vector
    vector_zeros=zeros(num_c*schindler_years,1);

    %Create the boom and bust indicator
    boom_bust_indicator=[vector_country vector_years vector_zeros];

    %Create matrix for boom and bust indicator. 1 when there is a boom, 2 when
    %there is a bust, 0 when there is neither a boom nor a bust
    for k=1:num_boom
        for i=1:size(boom_bust_indicator,1)
            for j=1:size(boom_bust_indicator,1)
                if and(boom_matrix(k,1)==boom_bust_indicator(i,1),boom_matrix(k,2)==boom_bust_indicator(j,2))
                   boom_bust_indicator(boom_bust_indicator(j,2)+schindler_years*(boom_bust_indicator(i,1)-1),3)=1;
                end
            end
        end
    end

    for k=1:num_bust
        for i=1:size(boom_bust_indicator,1)
            for j=1:size(boom_bust_indicator,1)
                if and(bust_matrix(k,1)==boom_bust_indicator(i,1),bust_matrix(k,2)==boom_bust_indicator(j,2))
                   boom_bust_indicator(boom_bust_indicator(j,2)+schindler_years*(boom_bust_indicator(i,1)-1),3)=2;
                end
            end
        end
    end

    %CHANGE MANUALLY!!!!!!!
    %Set equal to zero the years and country where we don't have observations
    %for the exchange rate regime either in that year or in the year
    %before or after
    for j=1:size(boom_bust_indicator,1)
           if boom_bust_indicator(j,2)==16 
               boom_bust_indicator(j,3)=0;
            elseif boom_bust_indicator(j,2)==17
               boom_bust_indicator(j,3)=0;
            elseif and(boom_bust_indicator(j,1)==1,boom_bust_indicator(j,2)<=7)%Angola
                boom_bust_indicator(j,3)=0;
            elseif and(boom_bust_indicator(j,1)==50,boom_bust_indicator(j,2)<=7)%Oman
                boom_bust_indicator(j,3)=0;
            elseif and(boom_bust_indicator(j,1)==72,boom_bust_indicator(j,2)<=7)%UAE
                boom_bust_indicator(j,3)=0;
            elseif and(boom_bust_indicator(j,1)==76,boom_bust_indicator(j,2)<=7)%Uzbekistan
                boom_bust_indicator(j,3)=0;

          end
    end

    %CHANGE MANUALLY!!!!!!!
    %Eliminate bomm/bust where the exchnage regime values in 1994 is not as
    %in 1995. To be done manually because data matrix starts from 1995.
    %Eliminate no boom, only eliminate additional bust for Finland, Mexico
    %and South Africa
    boom_bust_indicator(358,3)=0;
    boom_bust_indicator(732,3)=0;
    boom_bust_indicator(1004,3)=0;
    
    %Create matrices for output gap and detrended overall index for the five
    %different exchnage regime
    count_boom=ones(1,5);
    count_bust=ones(1,5);
    first_regime_boom=zeros(1,7,2);
    second_regime_boom=zeros(1,7,2);
    third_regime_boom=zeros(1,7,2);
    fourth_regime_boom=zeros(1,7,2);
    fifth_regime_boom=zeros(1,7,2);
    first_regime_bust=zeros(1,7,2);
    second_regime_bust=zeros(1,7,2);
    third_regime_bust=zeros(1,7,2);
    fourth_regime_bust=zeros(1,7,2);
    fifth_regime_bust=zeros(1,7,2);

    %BOOM
    for i=1:size(boom_bust_indicator,1)
        if boom_bust_indicator(i,3)==1 & boom_bust_indicator(i,2)==1
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_boom(count_boom(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                first_regime_boom(count_boom(1,1),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,1)=count_boom(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2  & aggregate_ex_regime(i+1,1)==2
                second_regime_boom(count_boom(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                second_regime_boom(count_boom(1,2),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,2)=count_boom(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_boom(count_boom(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                third_regime_boom(count_boom(1,3),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,3)=count_boom(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4  & aggregate_ex_regime(i+1,1)==4
                fourth_regime_boom(count_boom(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fourth_regime_boom(count_boom(1,4),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,4)=count_boom(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5  & aggregate_ex_regime(i+1,1)==5
                fifth_regime_boom(count_boom(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fifth_regime_boom(count_boom(1,5),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,5)=count_boom(1,5)+1;
            end
                
        elseif boom_bust_indicator(i,3)==1 & boom_bust_indicator(i,2)==2
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i-1,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_boom(count_boom(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                first_regime_boom(count_boom(1,1),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,1)=count_boom(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2 & aggregate_ex_regime(i-1,1)==2 & aggregate_ex_regime(i+1,1)==2
                second_regime_boom(count_boom(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                second_regime_boom(count_boom(1,2),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,2)=count_boom(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i-1,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_boom(count_boom(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                third_regime_boom(count_boom(1,3),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,3)=count_boom(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4 & aggregate_ex_regime(i-1,1)==4 & aggregate_ex_regime(i+1,1)==4
                fourth_regime_boom(count_boom(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fourth_regime_boom(count_boom(1,4),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,4)=count_boom(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_boom(count_boom(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fifth_regime_boom(count_boom(1,5),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,5)=count_boom(1,5)+1;
            end
        
        elseif boom_bust_indicator(i,3)==1 & boom_bust_indicator(i,2)==15
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i-1,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_boom(count_boom(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                first_regime_boom(count_boom(1,1),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_boom(1,1)=count_boom(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2 & aggregate_ex_regime(i-1,1)==2 & aggregate_ex_regime(i+1,1)==2
                second_regime_boom(count_boom(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                second_regime_boom(count_boom(1,2),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_boom(1,2)=count_boom(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i-1,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_boom(count_boom(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                third_regime_boom(count_boom(1,3),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_boom(1,3)=count_boom(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4 & aggregate_ex_regime(i-1,1)==4 & aggregate_ex_regime(i+1,1)==4
                fourth_regime_boom(count_boom(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                fourth_regime_boom(count_boom(1,4),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_boom(1,4)=count_boom(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_boom(count_boom(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                fifth_regime_boom(count_boom(1,5),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_boom(1,5)=count_boom(1,5)+1;
            end
        
        elseif boom_bust_indicator(i,3)==1 & boom_bust_indicator(i,2)~=1 & boom_bust_indicator(i,2)~=2 & boom_bust_indicator(i,2)~=15
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i-1,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_boom(count_boom(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                first_regime_boom(count_boom(1,1),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,1)=count_boom(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2 & aggregate_ex_regime(i-1,1)==2 & aggregate_ex_regime(i+1,1)==2
                second_regime_boom(count_boom(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                second_regime_boom(count_boom(1,2),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,2)=count_boom(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i-1,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_boom(count_boom(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                third_regime_boom(count_boom(1,3),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,3)=count_boom(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4 & aggregate_ex_regime(i-1,1)==4 & aggregate_ex_regime(i+1,1)==4
                fourth_regime_boom(count_boom(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fourth_regime_boom(count_boom(1,4),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,4)=count_boom(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_boom(count_boom(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fifth_regime_boom(count_boom(1,5),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_boom(1,5)=count_boom(1,5)+1;
            end
        end
    end

    %BUST
    for i=1:size(boom_bust_indicator,1)
        if boom_bust_indicator(i,3)==2 & boom_bust_indicator(i,2)==1
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_bust(count_bust(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                first_regime_bust(count_bust(1,1),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,1)=count_bust(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2  & aggregate_ex_regime(i+1,1)==2
                second_regime_bust(count_bust(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                second_regime_bust(count_bust(1,2),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,2)=count_bust(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3  & aggregate_ex_regime(i+1,1)==3
                third_regime_bust(count_bust(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                third_regime_bust(count_bust(1,3),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,3)=count_bust(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4  & aggregate_ex_regime(i+1,1)==4
                fourth_regime_bust(count_bust(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fourth_regime_bust(count_bust(1,4),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,4)=count_bust(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_bust(count_bust(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fifth_regime_bust(count_bust(1,5),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, nan, aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,5)=count_bust(1,5)+1;
            end
            
        elseif boom_bust_indicator(i,3)==2 & boom_bust_indicator(i,2)==2
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i-1,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_bust(count_bust(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                first_regime_bust(count_bust(1,1),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,1)=count_bust(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2 & aggregate_ex_regime(i-1,1)==2 & aggregate_ex_regime(i+1,1)==2
                second_regime_bust(count_bust(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                second_regime_bust(count_bust(1,2),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,2)=count_bust(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i-1,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_bust(count_bust(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                third_regime_bust(count_bust(1,3),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,3)=count_bust(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4 & aggregate_ex_regime(i-1,1)==4 & aggregate_ex_regime(i+1,1)==4
                fourth_regime_bust(count_bust(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fourth_regime_bust(count_bust(1,4),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,4)=count_bust(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_bust(count_bust(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fifth_regime_bust(count_bust(1,5),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), nan, aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,5)=count_bust(1,5)+1;
            end

        elseif boom_bust_indicator(i,3)==2 & boom_bust_indicator(i,2)==15
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i-1,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_bust(count_bust(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                first_regime_bust(count_bust(1,1),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_bust(1,1)=count_bust(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2 & aggregate_ex_regime(i-1,1)==2 & aggregate_ex_regime(i+1,1)==2
                second_regime_bust(count_bust(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                second_regime_bust(count_bust(1,2),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_bust(1,2)=count_bust(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i-1,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_bust(count_bust(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                third_regime_bust(count_bust(1,3),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_bust(1,3)=count_bust(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4 & aggregate_ex_regime(i-1,1)==4 & aggregate_ex_regime(i+1,1)==4
                fourth_regime_bust(count_bust(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                fourth_regime_bust(count_bust(1,4),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_bust(1,4)=count_bust(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_bust(count_bust(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), nan];
                fifth_regime_bust(count_bust(1,5),:,2)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), nan];
                count_bust(1,5)=count_bust(1,5)+1;
            end
                
        elseif boom_bust_indicator(i,3)==2 & boom_bust_indicator(i,2)~=1 & boom_bust_indicator(i,2)~=2 & boom_bust_indicator(i,2)~=15
            if aggregate_ex_regime(i,1)==1 & aggregate_ex_regime(i-1,1)==1 & aggregate_ex_regime(i+1,1)==1
                first_regime_bust(count_bust(1,1),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                first_regime_bust(count_bust(1,1),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,1)=count_bust(1,1)+1;
            elseif aggregate_ex_regime(i,1)==2 & aggregate_ex_regime(i-1,1)==2 & aggregate_ex_regime(i+1,1)==2
                second_regime_bust(count_bust(1,2),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                second_regime_bust(count_bust(1,2),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,2)=count_bust(1,2)+1;
            elseif aggregate_ex_regime(i,1)==3 & aggregate_ex_regime(i-1,1)==3 & aggregate_ex_regime(i+1,1)==3
                third_regime_bust(count_bust(1,3),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                third_regime_bust(count_bust(1,3),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,3)=count_bust(1,3)+1;
            elseif aggregate_ex_regime(i,1)==4 & aggregate_ex_regime(i-1,1)==4 & aggregate_ex_regime(i+1,1)==4
                fourth_regime_bust(count_bust(1,4),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fourth_regime_bust(count_bust(1,4),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,4)=count_bust(1,4)+1;
            elseif aggregate_ex_regime(i,1)==5 & aggregate_ex_regime(i-1,1)==5 & aggregate_ex_regime(i+1,1)==5
                fifth_regime_bust(count_bust(1,5),:,1)=[boom_bust_indicator(i,1), boom_bust_indicator(i,2), aggregate_xt(i-2,1), aggregate_xt(i-1,1), aggregate_xt(i,1), aggregate_xt(i+1,1), aggregate_xt(i+2,1)];
                fifth_regime_bust(count_bust(1,5),:,2)=[boom_bust_indicator(i,1) boom_bust_indicator(i,2), aggregate_overall_indext(i-2,1), aggregate_overall_indext(i-1,1), aggregate_overall_indext(i,1), aggregate_overall_indext(i+1,1), aggregate_overall_indext(i+2,1)];
                count_bust(1,5)=count_bust(1,5)+1;
            end
        end
    end
      
    %Calculate average of output gap and overall index for each exchange regime
    %group
    %BOOM
    first_xt_average_boom(1,:)=[nanmean(first_regime_boom(:,3,1),1) nanmean(first_regime_boom(:,4,1),1) nanmean(first_regime_boom(:,5,1),1) nanmean(first_regime_boom(:,6,1),1) nanmean(first_regime_boom(:,7,1),1)];
    second_xt_average_boom(1,:)=[nanmean(second_regime_boom(:,3,1),1) nanmean(second_regime_boom(:,4,1),1) nanmean(second_regime_boom(:,5,1),1) nanmean(second_regime_boom(:,6,1),1) nanmean(second_regime_boom(:,7,1),1)];
    third_xt_average_boom(1,:)=[nanmean(third_regime_boom(:,3,1),1) nanmean(third_regime_boom(:,4,1),1) nanmean(third_regime_boom(:,5,1),1) nanmean(third_regime_boom(:,6,1),1) nanmean(third_regime_boom(:,7,1),1)];
    fourth_xt_average_boom(1,:)=[nanmean(fourth_regime_boom(:,3,1),1) nanmean(fourth_regime_boom(:,4,1),1) nanmean(fourth_regime_boom(:,5,1),1) nanmean(fourth_regime_boom(:,6,1),1) nanmean(fourth_regime_boom(:,7,1),1)];
    fifth_xt_average_boom(1,:)=[nanmean(fifth_regime_boom(:,3,1),1) nanmean(fifth_regime_boom(:,4,1)) nanmean(fifth_regime_boom(:,5,1),1) nanmean(fifth_regime_boom(:,6,1),1) nanmean(fifth_regime_boom(:,7,1),1)];

    first_overall_average_boom(1,:)=[nanmean(first_regime_boom(:,3,2),1) nanmean(first_regime_boom(:,4,2),1) nanmean(first_regime_boom(:,5,2),1) nanmean(first_regime_boom(:,6,2),1) nanmean(first_regime_boom(:,7,2),1)];
    second_overall_average_boom(1,:)=[nanmean(second_regime_boom(:,3,2),1) nanmean(second_regime_boom(:,4,2),1) nanmean(second_regime_boom(:,5,2),1) nanmean(second_regime_boom(:,6,2),1) nanmean(second_regime_boom(:,7,2),1)];
    third_overall_average_boom(1,:)=[nanmean(third_regime_boom(:,3,2),1) nanmean(third_regime_boom(:,4,2),1) nanmean(third_regime_boom(:,5,2),1) nanmean(third_regime_boom(:,6,2),1) nanmean(third_regime_boom(:,7,2),1)];
    fourth_overall_average_boom(1,:)=[nanmean(fourth_regime_boom(:,3,2),1) nanmean(fourth_regime_boom(:,4,2),1) nanmean(fourth_regime_boom(:,5,2),1) nanmean(fourth_regime_boom(:,6,2),1) nanmean(fourth_regime_boom(:,7,2),1)];
    fifth_overall_average_boom(1,:)=[nanmean(fifth_regime_boom(:,3,2),1) nanmean(fifth_regime_boom(:,4,2),1) nanmean(fifth_regime_boom(:,5,2),1) nanmean(fifth_regime_boom(:,6,2),1) nanmean(fifth_regime_boom(:,7,2),1)];

    %BUST
    first_xt_average_bust(1,:)=[nanmean(first_regime_bust(:,3,1),1) nanmean(first_regime_bust(:,4,1),1) nanmean(first_regime_bust(:,5,1),1) nanmean(first_regime_bust(:,6,1),1) nanmean(first_regime_bust(:,7,1),1)];
    second_xt_average_bust(1,:)=[nanmean(second_regime_bust(:,3,1),1) nanmean(second_regime_bust(:,4,1),1) nanmean(second_regime_bust(:,5,1),1) nanmean(second_regime_bust(:,6,1),1) nanmean(second_regime_bust(:,7,1),1)];
    third_xt_average_bust(1,:)=[nanmean(third_regime_bust(:,3,1),1) nanmean(third_regime_bust(:,4,1),1) nanmean(third_regime_bust(:,5,1),1) nanmean(third_regime_bust(:,6,1),1) nanmean(third_regime_bust(:,7,1),1)];
    fourth_xt_average_bust(1,:)=[nanmean(fourth_regime_bust(:,3,1),1) nanmean(fourth_regime_bust(:,4,1),1) nanmean(fourth_regime_bust(:,5,1),1) nanmean(fourth_regime_bust(:,6,1),1) nanmean(fourth_regime_bust(:,7,1),1)];
    fifth_xt_average_bust(1,:)=[nanmean(fifth_regime_bust(:,3,1),1) nanmean(fifth_regime_bust(:,4,1)) nanmean(fifth_regime_bust(:,5,1),1) nanmean(fifth_regime_bust(:,6,1),1) nanmean(fifth_regime_bust(:,7,1),1)];
 
    first_overall_average_bust(1,:)=[nanmean(first_regime_bust(:,3,2),1) nanmean(first_regime_bust(:,4,2),1) nanmean(first_regime_bust(:,5,2),1) nanmean(first_regime_bust(:,6,2),1) nanmean(first_regime_bust(:,7,2),1)];
    second_overall_average_bust(1,:)=[nanmean(second_regime_bust(:,3,2),1) nanmean(second_regime_bust(:,4,2),1) nanmean(second_regime_bust(:,5,2),1) nanmean(second_regime_bust(:,6,2),1) nanmean(second_regime_bust(:,7,2),1)];
    third_overall_average_bust(1,:)=[nanmean(third_regime_bust(:,3,2),1) nanmean(third_regime_bust(:,4,2),1) nanmean(third_regime_bust(:,5,2),1) nanmean(third_regime_bust(:,6,2),1) nanmean(third_regime_bust(:,7,2),1)];
    fourth_overall_average_bust(1,:)=[nanmean(fourth_regime_bust(:,3,2),1) nanmean(fourth_regime_bust(:,4,2),1) nanmean(fourth_regime_bust(:,5,2),1) nanmean(fourth_regime_bust(:,6,2),1) nanmean(fourth_regime_bust(:,7,2),1)];
    fifth_overall_average_bust(1,:)=[nanmean(fifth_regime_bust(:,3,2),1) nanmean(fifth_regime_bust(:,4,2),1) nanmean(fifth_regime_bust(:,5,2),1) nanmean(fifth_regime_bust(:,6,2),1) nanmean(fifth_regime_bust(:,7,2),1)];

    %Calculate standard deviations for index in each exchange rate regime group
    %BOOM
    first_overall_std_boom(1,:)=[nanstd(first_regime_boom(:,3,2),0,1) nanstd(first_regime_boom(:,4,2),0,1) nanstd(first_regime_boom(:,5,2),0,1) nanstd(first_regime_boom(:,6,2),0,1) nanstd(first_regime_boom(:,7,2),0,1)];
    second_overall_std_boom(1,:)=[nanstd(second_regime_boom(:,3,2),0,1) nanstd(second_regime_boom(:,4,2),0,1) nanstd(second_regime_boom(:,5,2),0,1) nanstd(second_regime_boom(:,6,2),0,1) nanstd(second_regime_boom(:,7,2),0,1)];
    third_overall_std_boom(1,:)=[nanstd(third_regime_boom(:,3,2),0,1) nanstd(third_regime_boom(:,4,2),0,1) nanstd(third_regime_boom(:,5,2),0,1) nanstd(third_regime_boom(:,6,2),0,1) nanstd(third_regime_boom(:,7,2),0,1)];
    fourth_overall_std_boom(1,:)=[nanstd(fourth_regime_boom(:,3,2),0,1) nanstd(fourth_regime_boom(:,4,2),0,1) nanstd(fourth_regime_boom(:,5,2),0,1) nanstd(fourth_regime_boom(:,6,2),0,1) nanstd(fourth_regime_boom(:,7,2),0,1)];
    fifth_overall_std_boom(1,:)=[nanstd(fifth_regime_boom(:,3,2),0,1) nanstd(fifth_regime_boom(:,4,2),0,1) nanstd(fifth_regime_boom(:,5,2),0,1) nanstd(fifth_regime_boom(:,6,2),0,1) nanstd(fifth_regime_boom(:,7,2),0,1)];

    %BUST
    first_overall_std_bust(1,:)=[nanstd(first_regime_bust(:,3,2),0,1) nanstd(first_regime_bust(:,4,2),0,1) nanstd(first_regime_bust(:,5,2),0,1) nanstd(first_regime_bust(:,6,2),0,1) nanstd(first_regime_bust(:,7,2),0,1)];
    second_overall_std_bust(1,:)=[nanstd(second_regime_bust(:,3,2),0,1) nanstd(second_regime_bust(:,4,2),0,1) nanstd(second_regime_bust(:,5,2),0,1) nanstd(second_regime_bust(:,6,2),0,1) nanstd(second_regime_bust(:,7,2),0,1)];
    third_overall_std_bust(1,:)=[nanstd(third_regime_bust(:,3,2),0,1) nanstd(third_regime_bust(:,4,2),0,1) nanstd(third_regime_bust(:,5,2),0,1) nanstd(third_regime_bust(:,6,2),0,1) nanstd(third_regime_bust(:,7,2),0,1)];
    fourth_overall_std_bust(1,:)=[nanstd(fourth_regime_bust(:,3,2),0,1) nanstd(fourth_regime_bust(:,4,2),0,1) nanstd(fourth_regime_bust(:,5,2),0,1) nanstd(fourth_regime_bust(:,6,2),0,1) nanstd(fourth_regime_bust(:,7,2),0,1)];
    fifth_overall_std_bust(1,:)=[nanstd(fifth_regime_bust(:,3,2),0,1) nanstd(fifth_regime_bust(:,4,2),0,1) nanstd(fifth_regime_bust(:,5,2),0,1) nanstd(fifth_regime_bust(:,6,2),0,1) nanstd(fifth_regime_bust(:,7,2),0,1)];
    
    %Create interval confidence
    %BOOM
    for i=1:num_column
        first_upper_bound_boom(1,i)=first_overall_average_boom(1,i)+2*first_overall_std_boom(1,i);
        first_lower_bound_boom(1,i)=first_overall_average_boom(1,i)-2*first_overall_std_boom(1,i);
    end

    for i=1:num_column
        second_upper_bound_boom(1,i)=second_overall_average_boom(1,i)+2*second_overall_std_boom(1,i);
        second_lower_bound_boom(1,i)=second_overall_average_boom(1,i)-2*second_overall_std_boom(1,i);
    end

    for i=1:num_column
        third_upper_bound_boom(1,i)=third_overall_average_boom(1,i)+2*third_overall_std_boom(1,i);
        third_lower_bound_boom(1,i)=third_overall_average_boom(1,i)-2*third_overall_std_boom(1,i);
    end

    for i=1:num_column
        fourth_upper_bound_boom(1,i)=fourth_overall_average_boom(1,i)+2*fourth_overall_std_boom(1,i);
        fourth_lower_bound_boom(1,i)=fourth_overall_average_boom(1,i)-2*fourth_overall_std_boom(1,i);
    end

    for i=1:num_column
        fifth_upper_bound_boom(1,i)=fifth_overall_average_boom(1,i)+2*fifth_overall_std_boom(1,i);
        fifth_lower_bound_boom(1,i)=fifth_overall_average_boom(1,i)-2*fifth_overall_std_boom(1,i);
    end

    %BUST
    for i=1:num_column
        first_upper_bound_bust(1,i)=first_overall_average_bust(1,i)+2*first_overall_std_bust(1,i);
        first_lower_bound_bust(1,i)=first_overall_average_bust(1,i)-2*first_overall_std_bust(1,i);
    end

    for i=1:num_column
        second_upper_bound_bust(1,i)=second_overall_average_bust(1,i)+2*second_overall_std_bust(1,i);
        second_lower_bound_bust(1,i)=second_overall_average_bust(1,i)-2*second_overall_std_bust(1,i);
    end

    for i=1:num_column
        third_upper_bound_bust(1,i)=third_overall_average_bust(1,i)+2*third_overall_std_bust(1,i);
        third_lower_bound_bust(1,i)=third_overall_average_bust(1,i)-2*third_overall_std_bust(1,i);
    end

    for i=1:num_column
        fourth_upper_bound_bust(1,i)=fourth_overall_average_bust(1,i)+2*fourth_overall_std_bust(1,i);
        fourth_lower_bound_bust(1,i)=fourth_overall_average_bust(1,i)-2*fourth_overall_std_bust(1,i);
    end

    for i=1:num_column
        fifth_upper_bound_bust(1,i)=fifth_overall_average_bust(1,i)+2*fifth_overall_std_bust(1,i);
        fifth_lower_bound_bust(1,i)=fifth_overall_average_bust(1,i)-2*fifth_overall_std_bust(1,i);
    end

    %Create matrix for all output gap averages for booms
    xt_average_matrix_boom(:,:,1)=first_xt_average_boom;
    xt_average_matrix_boom(:,:,2)=second_xt_average_boom;
    xt_average_matrix_boom(:,:,3)=third_xt_average_boom;
    xt_average_matrix_boom(:,:,4)=fourth_xt_average_boom;
    xt_average_matrix_boom(:,:,5)=fifth_xt_average_boom;

    %Create matrix for all output gap averages for bust
    xt_average_matrix_bust(:,:,1)=first_xt_average_bust;
    xt_average_matrix_bust(:,:,2)=second_xt_average_bust;
    xt_average_matrix_bust(:,:,3)=third_xt_average_bust;
    xt_average_matrix_bust(:,:,4)=fourth_xt_average_bust;
    xt_average_matrix_bust(:,:,5)=fifth_xt_average_bust;
    
    %Create matrix for all index averages for booms
    overall_average_matrix_boom(:,:,1)=first_overall_average_boom;
    overall_average_matrix_boom(:,:,2)=second_overall_average_boom;
    overall_average_matrix_boom(:,:,3)=third_overall_average_boom;
    overall_average_matrix_boom(:,:,4)=fourth_overall_average_boom;
    overall_average_matrix_boom(:,:,5)=fifth_overall_average_boom;
 
    %Create matrix for all index averages for bust
    overall_average_matrix_bust(:,:,1)=first_overall_average_bust;
    overall_average_matrix_bust(:,:,2)=second_overall_average_bust;
    overall_average_matrix_bust(:,:,3)=third_overall_average_bust;
    overall_average_matrix_bust(:,:,4)=fourth_overall_average_bust;
    overall_average_matrix_bust(:,:,5)=fifth_overall_average_bust;
        
    %Create matrix for all index confidence interval for booms
    overall_interval_matrix_boom(:,:,1)=[first_lower_bound_boom;first_upper_bound_boom];
    overall_interval_matrix_boom(:,:,2)=[second_lower_bound_boom;second_upper_bound_boom];
    overall_interval_matrix_boom(:,:,3)=[third_lower_bound_boom;third_upper_bound_boom];
    overall_interval_matrix_boom(:,:,4)=[fourth_lower_bound_boom;fourth_upper_bound_boom];
    overall_interval_matrix_boom(:,:,5)=[fifth_lower_bound_boom;fifth_upper_bound_boom];

    %Create matrix for all index confidence interval for busts
    overall_interval_matrix_bust(:,:,1)=[first_lower_bound_bust;first_upper_bound_bust];
    overall_interval_matrix_bust(:,:,2)=[second_lower_bound_bust;second_upper_bound_bust];
    overall_interval_matrix_bust(:,:,3)=[third_lower_bound_bust;third_upper_bound_bust];
    overall_interval_matrix_bust(:,:,4)=[fourth_lower_bound_bust;fourth_upper_bound_bust];
    overall_interval_matrix_bust(:,:,5)=[fifth_lower_bound_bust;fifth_upper_bound_bust];

    %Calculate # of booms in each regime
    %CHANGE MANUALLY!!! REGIME5 We substract 1 because is the initial zero row
    num_regime1_boom=size(first_regime_boom(:,1,1),1);
    num_regime2_boom=size(second_regime_boom(:,1,1),1);
    num_regime3_boom=size(third_regime_boom(:,1,1),1);
    num_regime4_boom=size(fourth_regime_boom(:,1,1),1);
    num_regime5_boom=size(fifth_regime_boom(:,1,1),1)-1;

    num_regime_boom=[num_regime1_boom num_regime2_boom num_regime3_boom num_regime4_boom num_regime5_boom];
    
    %Calculate # of bust in each regime
    %CHANGE MANUALLY!!! REGIME5 We substract 1 because is the initial zero row
    num_regime1_bust=size(first_regime_bust(:,1,1),1);
    num_regime2_bust=size(second_regime_bust(:,1,1),1);
    num_regime3_bust=size(third_regime_bust(:,1,1),1);
    num_regime4_bust=size(fourth_regime_bust(:,1,1),1);
    num_regime5_bust=size(fifth_regime_bust(:,1,1),1)-1;
    
   num_regime_bust=[num_regime1_bust num_regime2_bust num_regime3_bust num_regime4_bust num_regime5_bust];



end

