function [ y_adv, y_mid, y_poor, y_vpoor ] = aggregate_group_special_bond( num_var, x_adv, x_mid, x_poor, x_vpoor)

% SPECIAL FUNCTION FOR BOND INDEX DUE TO TWO MISSING VALUES IN THE
% SCHINDLER INDEX IN ALL COUNTRIES OF THE SAMPLE

% PURPOSE: CREATE COUNTRY GROUPS AGGREGATED VARIABLE FOR CALCULATING THE 
% CORRELATION IN EACH COUNTRY GROUPS USING DISAGGREGATED COUNTRY GROUP
% VARIABLE FOR BOND INDEX
% 
% 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
%     - x_vpoor: DISAGGREGATED VARIABLE FOR HIP COUNTRIES
%     
% OUTPUT:
%     - y_adv: AGGREGATED VARIABLE FOR ADVANCED ECONOMIES
%     - y_mid: AGGREGATED VARIABLE FOR EMERGING MARKETS
%     - y_poor: AGGREGATED VARIABLE FOR DEVELOPING ECONOMIES
%     - y_vpoor: AGGREGATED VARIABLE FOR HIP COUNTRIES



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

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

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

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

    %Create a vector for very poor countries
    for k=1:num_var
        for j=1:schindler_years-2
            for i=1:num_vpoor
                y_vpoor(j+(schindler_years-2)*(i-1),k)=x_vpoor(i,j,k);
            end
        end
    end


end


