function [ y1_adv, y1_mid, y1_poor, y2_adv, y2_mid, y2_poor ] = aggregate_group_one( num_var1, num_var2, x1_adv, x1_mid, x1_poor, x2_adv, x2_mid, x2_poor)


% PURPOSE: CREATE LAGS/LEADS COUNTRY GROUPS AGGREGATED VARIABLE FOR CALCULATING THE 
% CORRELATION IN EACH COUNTRY GROUPS USING DISAGGREGATED COUNTRY GROUP VARIABLE
% 
% INPUT:
%     - num_var1: NUMBER OF TIME SERIES FOR THE FIRST VARIABLE
%     - num_var2: NUMBER OF TIME SERIES FOR THE SECOND VARIABLE
%     - x1_adv: DISAGGREGATED FIRST VARIABLE FOR ADVANCED ECONOMIES
%     - x1_mid: DISAGGREGATED FIRST VARIABLE FOR EMERGING MARKETS
%     - x1_poor: DISAGGREGATED FIRST VARIABLE FOR DEVELOPING ECONOMIES
%     - x2_adv: DISAGGREGATED SECOND VARIABLE FOR ADVANCED ECONOMIES
%     - x2_mid: DISAGGREGATED SECOND VARIABLE FOR EMERGING MARKETS
%     - x2_poor: DISAGGREGATED SECOND VARIABLE FOR DEVELOPING ECONOMIES
%
%
% OUTPUT:
%     - y1_adv: AGGREGATED FIRST VARIABLE FOR ADVANCED ECONOMIES
%     - y1_mid: AGGREGATED FIRST VARIABLE FOR EMERGING MARKETS
%     - y1_poor: AGGREGATED FIRST VARIABLE FOR DEVELOPING ECONOMIES
%     - y2_adv: AGGREGATED SECOND VARIABLE FOR ADVANCED ECONOMIES
%     - y2_mid: AGGREGATED SECOND VARIABLE FOR EMERGING MARKETS
%     - y2_poor: AGGREGATED SECOND VARIABLE FOR DEVELOPING ECONOMIES

% This function is needed because aggregated lagged and leaded values
% involve a different structure of the aggregated matrix.

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

    %Create vectors for advanced economies
    for k=1:num_var1
        for j=1:schindler_years-1
            for i=1:num_adv
                y1_adv(j+(schindler_years-1)*(i-1),k)=x1_adv(i,j,k);
            end
        end
    end

    for k=1:num_var2
        for j=2:schindler_years
            for i=1:num_adv
                y2_adv(j-1+(schindler_years-1)*(i-1),k)=x2_adv(i,j,k);
            end
        end
    end
    
    %Create vectors for midlle income economies
    for k=1:num_var1
        for j=1:schindler_years-1
            for i=1:num_mid
                y1_mid(j+(schindler_years-1)*(i-1),k)=x1_mid(i,j,k);
            end
        end
    end

    for k=1:num_var2
        for j=2:schindler_years
            for i=1:num_mid
                y2_mid(j-1+(schindler_years-1)*(i-1),k)=x2_mid(i,j,k);
            end
        end
    end

    %Create vectors for poor economies
    for k=1:num_var1
        for j=1:schindler_years-1
            for i=1:num_poor
                y1_poor(j+(schindler_years-1)*(i-1),k)=x1_poor(i,j,k);
            end
        end
    end

    for k=1:num_var2
        for j=2:schindler_years
            for i=1:num_poor
                y2_poor(j-1+(schindler_years-1)*(i-1),k)=x2_poor(i,j,k);
            end
        end
    end


end


