clear all
clc
close all

A=[1;5;10];

AUX=[];
for ii=1:3
TEST=[];
CIL=[];
CIU=[];
alpha=A(ii);
t_up=100-alpha/2;
t_bot=alpha/2;
load('../Section5/results_Y_L_RECESSIONS')

VAR_TEST_A=Bootstrapped_Values2(:,2)-Bootstrapped_Values2(:,1);
var_A=Estimated_Values_2ndstep(2)-Estimated_Values_2ndstep(1);


load('../Section5/results_Y_N_RECESSIONS')

VAR_TEST_B=Bootstrapped_Values2(:,2)-Bootstrapped_Values2(:,1);
var_B=Estimated_Values_2ndstep(2)-Estimated_Values_2ndstep(1);

pp_test1=var_A-var_B;

VAR_TEST=VAR_TEST_A-VAR_TEST_B;

CI_perc = prctile([VAR_TEST],[2*t_bot 100-2*t_bot],1)';

Estim=[pp_test1];
CI_perc_L=2*Estim-CI_perc(:,2);
CI_perc_U=2*Estim-CI_perc(:,1);

TEST=[TEST;Estim];
CIL=[CIL;CI_perc_L];
CIU=[CIU;CI_perc_U];

load('../Section5/results_Y_L_RECESSIONS')
VAR_TEST_A=Bootstrapped_Values2(:,2)-Bootstrapped_Values2(:,1);
var_A=Estimated_Values_2ndstep(2)-Estimated_Values_2ndstep(1);

load('../Section5/results_Y_B_RECESSIONS')
VAR_TEST_B=Bootstrapped_Values2(:,2)-Bootstrapped_Values2(:,1);
var_B=Estimated_Values_2ndstep(2)-Estimated_Values_2ndstep(1);

pp_test1=var_A-var_B;

VAR_TEST=VAR_TEST_A-VAR_TEST_B;

CI_perc = prctile([VAR_TEST],[2*t_bot 100-2*t_bot],1)';

Estim=[pp_test1];
CI_perc_L=2*Estim-CI_perc(:,2);
CI_perc_U=2*Estim-CI_perc(:,1);

TEST=[TEST;Estim];
CIL=[CIL;CI_perc_L];
CIU=[CIU;CI_perc_U];

load('../Section5/results_Y_L_RECESSIONS')
VAR_TEST_A=Bootstrapped_Values2(:,2)-Bootstrapped_Values2(:,1);
var_A=Estimated_Values_2ndstep(2)-Estimated_Values_2ndstep(1);

load('../Section5/results_Y_T_RECESSIONS')
VAR_TEST_B=Bootstrapped_Values2(:,2)-Bootstrapped_Values2(:,1);
var_B=Estimated_Values_2ndstep(2)-Estimated_Values_2ndstep(1);

pp_test1=var_A-var_B;

VAR_TEST=VAR_TEST_A-VAR_TEST_B;

CI_perc = prctile([VAR_TEST],[2*t_bot 100-2*t_bot],1)';

Estim=[pp_test1];
CI_perc_L=2*Estim-CI_perc(:,2);
CI_perc_U=2*Estim-CI_perc(:,1);

TEST=[TEST;Estim];
CIL=[CIL;CI_perc_L];
CIU=[CIU;CI_perc_U];

XX1=[TEST CIL CIU];
siga=((XX1(:,2)>0 & XX1(:,3)>0)+(XX1(:,2)<0 & XX1(:,3)<0));
sigb=((XX1(:,2)>0 & XX1(:,3)>0)& XX1(:,1)>0) | ((XX1(:,2)<0 & XX1(:,3)<0) & (XX1(:,1)<0) );

sig=(100-alpha)*siga.*sigb;
AUX=[AUX sig];

end

significance=max(AUX,[],2);
clearvars -except significance TEST AUX

name = {'[m_{4}^{η,e}-m_{4}^{η,c}]^{Y}-[m_{4}^{η,e}-m_{4}^{η,c}]^{Y-T}';...
        '[m_{4}^{η,e}-m_{4}^{η,c}]^{Y}-[m_{4}^{η,e}-m_{4}^{η,c}]^{T+bn}';...
        '[m_{4}^{η,e}-m_{4}^{η,c}]^{Y}-[m_{4}^{η,e}-m_{4}^{η,c}]^{T+bn-T}'};

TABLE_6_tau_4 = table(round(TEST,4),significance,'RowNames',name);
disp('Table 6 (tau=4):  Policy effects on the cyclicality of persistent risk')
disp(TABLE_6_tau_4)



