function [  jump_adv,  jump_mid,  jump_poor ] = country_groups_boom_bust( num_var, num_jump, jump_matrix_ref, jump_matrix )

% 
% PURPOSE: CREATE MATRICES FOR BOOM/BUST EPISODES DIVIDED BY COUNTRY GROUPS
% FOR OUTPUT GAP AND GROWTH RATE
% 
% INPUT:
%     -num_var: NUMBER OF TIME SERIES FOR THE VARIABLE OF INTEREST
%     -num_jump: NUMBER OF BOOM/BUST EPISODES
%     -jump_matrix_ref: MATRIX WITH REFERENCE TO BOOM/BUST EPISODES
%     -jump_matrix: MATRIX WITH BOOM/BUST VALUES
%     
% OUTPUT:
%     -jump_adv: BOOM/BUST EPISODES FOR ADVANCED ECONOMIES
%     -jump_mid: BOOM/BUST EPISODES FOR EMERGING MARKETS
%     -jump_poor: BOOM/BUST EPISODES FOR DEVELOPING ECONOMIES
% 

%Recall variable defined in the main script
global vect_adv num_adv vect_mid num_mid vect_poor num_poor
    %Create matrices for the boom episodes divided by country groups
    for i=1:num_var
        for j=1:num_jump
            for k=1:num_adv
                if vect_adv(1,k)==jump_matrix_ref(j,1)
                    jump_adv(j,:,i)=jump_matrix(j,:,i);
                end
            end
            for k=1:num_mid
                if vect_mid(1,k)==jump_matrix_ref(j,1)
                    jump_mid(j,:,i)=jump_matrix(j,:,i);
                end
            end
            for k=1:num_poor
                if vect_poor(1,k)==jump_matrix_ref(j,1)
                    jump_poor(j,:,i)=jump_matrix(j,:,i);
                end
            end
        end 
    end

    %Eliminate all rows with zero values
    jump_adv( ~any(jump_adv,2), : ) = [];
    jump_mid( ~any(jump_mid,2), : ) = [];
    jump_poor( ~any(jump_poor,2), : ) = [];


end


