function [ average_indext_values_jump_group, std_indext_values_jump_group,  upper_bound_jump_group, lower_bound_jump_group ] = average_boom_bust_country_group( num_var, indext_values_jump_group_overall, indext_values_jump_group_inflow, indext_values_jump_group_outflow )

% PURPOSE: CALCULATE THE AVERAGES, STANDARD DEVIATION AND CONFIDENCE INTERVAL
% FOR THE INDEXES AT DIFFERENT TIME HORIZONS FOR BOOM/BUST EPISODES IN EACH
% COUNTRY GROUP
% 
% INPUT:
%     -num_var: NUMBER OF VARIABLES
%     -indext_values_jump_group_overall: OVERALL DETRENDED INDEX VALUES FOR BOOM/BUST
%     -indext_values_jump_group_inflow: INFLOW DETRENDED INDEX VALUES FOR BOOM/BUST
%     -indext_values_jump_group_outflow: OUTFLOW DETRENDED INDEX VALUES FOR BOOM/BUST
% 
% OUTPUT:
%     -average_indext_values_jump_group: AVERAGES FOR ALL THREE INDEXES IN BOOM/BUST EPISODES
%     -std_indext_values_jump_group: STANDARD DEVIATION FOR ALL THREE INDEXES IN BOOM/BUST EPISODES
%     -upper_bound_jump_group: UPPER BOUND FOR ALL THREE INDEXES IN BOOM/BUST EPISODES
%     -lower_bound_jump_group: LOWER FOR ALL THREE INDEXES IN BOOM/BUST EPISODES

     
    %Average for the different time horizons
    for i=1:5
        average_indext_values_jump_group_overall(1,i)=nanmean(indext_values_jump_group_overall(:,i+1),1);
        average_indext_values_jump_group_inflow(1,i)=nanmean(indext_values_jump_group_inflow(:,i+1),1);
        average_indext_values_jump_group_outflow(1,i)=nanmean(indext_values_jump_group_outflow(:,i+1),1);
    end
    average_indext_values_jump_group(:,:,1)=average_indext_values_jump_group_overall;
    average_indext_values_jump_group(:,:,2)=average_indext_values_jump_group_inflow;
    average_indext_values_jump_group(:,:,3)=average_indext_values_jump_group_outflow;

    %Standard Deviation
    for i=1:5
        std_indext_values_jump_group_overall(1,i)=nanstd(indext_values_jump_group_overall(:,i+1),1);
        std_indext_values_jump_group_inflow(1,i)=nanstd(indext_values_jump_group_inflow(:,i+1),1);
        std_indext_values_jump_group_outflow(1,i)=nanstd(indext_values_jump_group_outflow(:,i+1),1);
    end

    std_indext_values_jump_group(:,:,1)=std_indext_values_jump_group_overall;
    std_indext_values_jump_group(:,:,2)=std_indext_values_jump_group_inflow;
    std_indext_values_jump_group(:,:,3)=std_indext_values_jump_group_outflow;


    %Confidence interval for the detrended index
    for j=1:num_var
        for i=1:5
            upper_bound_jump_group(1,i,j)=average_indext_values_jump_group(1,i,j)+ 2*std_indext_values_jump_group(1,i,j);
            lower_bound_jump_group(1,i,j)=average_indext_values_jump_group(1,i,j)- 2*std_indext_values_jump_group(1,i,j);
        end
    end

end

