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

% 
% PURPOSE: CREATE MATRICES FOR BOOM/BUST EPISODES DIVIDED BY COUNTRY GROUPS
% FOR THE INDEX
% 
% 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
%     -jump_vpoor: BOOM/BUST EPISODES FOR HIP COUNTRIES
% 

%Recall variable defined in the main script
global vect_adv num_adv vect_mid num_mid vect_poor num_poor vect_vpoor num_vpoor

    %Create matrices for the boom/bust 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
            for k=1:num_vpoor
                if vect_vpoor(1,k)==jump_matrix_ref(j,1)
                    jump_vpoor(j,:,i)=jump_matrix(j,:,i);
                end
            end
        end 
    end

end

