function [ y_adv, y_mid, y_poor ] = aggregate_group( num_var, x_adv, x_mid, x_poor)

% PURPOSE: CREATE COUNTRY GROUPS AGGREGATED VARIABLE FOR CALCULATING THE 
% CORRELATION IN EACH COUNTRY GROUPS USING DISAGGREGATED COUNTRY GROUP VARIABLE
% 
% INPUT:
%     - num_var: NUMBER OF TIME SERIES FOR THE VARIABLE
%     - x_adv: DISAGGREGATED VARIABLE FOR ADVANCED ECONOMIES
%     - x_mid: DISAGGREGATED VARIABLE FOR EMERGING MARKETS
%     - x_poor: DISAGGREGATED VARIABLE FOR DEVELOPING ECONOMIES
%     
% OUTPUT:
%     - y_adv: AGGREGATED VARIABLE FOR ADVANCED ECONOMIES
%     - y_mid: AGGREGATED VARIABLE FOR EMERGING MARKETS
%     - y_poor: AGGREGATED VARIABLE FOR DEVELOPING ECONOMIES


%Recall global variables define in the main script
global schindler_years num_adv num_mid num_poor

    %Create an aggregated vector for advanced economies
    for k=1:num_var
        for j=1:schindler_years
            for i=1:num_adv
                y_adv(j+schindler_years*(i-1),k)=x_adv(i,j,k);
            end
        end
    end

    %Create an aggregated vector for middle income countries
    for k=1:num_var
        for j=1:schindler_years
            for i=1:num_mid
                y_mid(j+schindler_years*(i-1),k)=x_mid(i,j,k);
            end
        end
    end

    %Create an aggregated vector for poor countries
    for k=1:num_var
        for j=1:schindler_years
            for i=1:num_poor
                y_poor(j+schindler_years*(i-1),k)=x_poor(i,j,k);
            end
        end
    end



end

