function [ corr_matrix_sort, legend_matrix_star, star_matrix, legend_matrix ] = star_zero( num_var, r, p )


% PURPOSE: ASSIGN STARS TO DIFFERENT SIGNIFICANCE LEVELS OF THE COUNTRY CORRELATIONS
% AND ORDER THEM IN ACCORDING TO SIGN AND PVALUE
% 
% INPUT:
%     -num_var:NUMBER OF VARIABLES
%     -r:CORRELATION
%     -p:PVALUE
%     
% OUTPUT:
%     -corr_matrix_sort:CORRELATION MATRIX SORTED
%     -legend_matrix_sort: NAMES COUNTRIES AND STARS SORTED
%     -star_matrix: STAR VECTOR SORTED
%     -legend_matrix: NAMES COUNTRIES SORTED
  
    
%Recall variables defined in the main script    
global num_c Countries

    %Create a counter for # of countries in the sample
    
    for j=1:num_c
        counter(j,1) = j;
    end

    for l=1:num_var
        corr_matrix(:,:,l)=[counter r(:,l) p(:,l)];

        %Sort the correlations values for sign and pvalue
        corr_matrix_sort(:,:,l)= sortrows(corr_matrix(:,:,l),2);

        %Create vector with the stars for the different significance levels 
        for i=1:num_c
            if corr_matrix_sort(i,3,l)<.01
                star_matrix(i,1,l)= {'***'};
            elseif and(corr_matrix_sort(i,3,l)>.01, corr_matrix_sort(i,3,l)<.05)
                star_matrix(i,1,l)={'**'};
            elseif and(corr_matrix_sort(i,3,l)>.05, corr_matrix_sort(i,3,l)<.1)
                star_matrix(i,1,l)={'*'};
            else
                star_matrix(i,1,l)={''};
            end
        end

        %Create a vector with the names of the countries sorted in the right order 
        for k=1:num_c
            for i=1:num_c
                 if i==corr_matrix_sort(k,1,l)
                    legend_matrix(k,1,l)=Countries(i,1);
                 end
            end
        end

        %Concatenate country names and stars
        legend_matrix_star(:,:,l)=strcat(legend_matrix(:,:,l),star_matrix(:,:,l));
    end   
end
















