function [ r_agg_matrix, p_agg_matrix, star_agg_matrix ] = aggregate_correlation( num_var, aggregate_x, aggregate_y )

% PURPOSE: CALCULATE THE CORRELATION BETWEEN THE AGGREGATED OUTPUT GAP OR GROWTH
% RATES AND THE AGGREGATED INDEX BOTH AT TIME T=0. THIS CORRELATION IS
% THE CORRELATION BETWEEN MATRICES WITH ALL OBSERVATIONS FOR ALL COUNTRIES.
% 
% INPUT:
%        - num_var: NUMBER OF TIME SERIES FOR THE INDEX
%        - aggregate_x: VECTOR OF OUTPUT GAP (OR GROWTH RATE???) TIME SERIES
%        - aggregate_y: MATRIX OF INDEXES TIME SERIES
% 
% OUTPUT:
%        - r_agg_matrix: RETURN THE CORRELATION VALUE
%        - p_agg_matrix: RETURN THE P-VALUE OF THE CORRELATION
%        - star_agg_matrix: RETURN A STRING WITH STARS FOR DIFFERENT SIGNIFICANCE LEVELS


%Calculate correlations between output gap (or growth rate) and index using the Matlab
%function corr
    for i=1:num_var
    [r_agg_matrix(:,i) p_agg_matrix(:,i)] = corr( aggregate_x, aggregate_y(:,i));

    %Reports only two decimals
    r_agg_matrix=roundTo(r_agg_matrix,2);
    
        %Assign stars for different significance levels
        if p_agg_matrix(:,i)<.01
                star_agg_matrix(:,i)= {'***'};
            elseif and(p_agg_matrix(:,i)>.01, p_agg_matrix(:,i)<.05)
                star_agg_matrix(:,i)={'**'};
            elseif and(p_agg_matrix(:,i)>.05, p_agg_matrix(:,i)<.1)
                star_agg_matrix(:,i)={'*'};
            else
                star_agg_matrix(:,i)={''};
        end
    end

end

