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')

SK_TEST_A=Bootstrapped_Values1(:,4)-Bootstrapped_Values1(:,3);
sk_A=Estimated_Values_1ststep(4)-Estimated_Values_1ststep(3);
VAR_TEST_A=Bootstrapped_Values1(:,2)-Bootstrapped_Values1(:,1);
var_A=Estimated_Values_1ststep(2)-Estimated_Values_1ststep(1);


load('../Section5/results_Y_N_RECESSIONS')

SK_TEST_B=Bootstrapped_Values1(:,4)-Bootstrapped_Values1(:,3);
sk_B=Estimated_Values_1ststep(4)-Estimated_Values_1ststep(3);
VAR_TEST_B=Bootstrapped_Values1(:,2)-Bootstrapped_Values1(:,1);
var_B=Estimated_Values_1ststep(2)-Estimated_Values_1ststep(1);

pp_test1=var_A-var_B;
pp_test2=sk_A-sk_B;

VAR_TEST=VAR_TEST_A-VAR_TEST_B;
SK_TEST=SK_TEST_A-SK_TEST_B;

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

Estim=[pp_test1;pp_test2];
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')
SK_TEST_A=Bootstrapped_Values1(:,4)-Bootstrapped_Values1(:,3);
sk_A=Estimated_Values_1ststep(4)-Estimated_Values_1ststep(3);
VAR_TEST_A=Bootstrapped_Values1(:,2)-Bootstrapped_Values1(:,1);
var_A=Estimated_Values_1ststep(2)-Estimated_Values_1ststep(1);

load('../Section5/results_Y_B_RECESSIONS')
SK_TEST_B=Bootstrapped_Values1(:,4)-Bootstrapped_Values1(:,3);
sk_B=Estimated_Values_1ststep(4)-Estimated_Values_1ststep(3);
VAR_TEST_B=Bootstrapped_Values1(:,2)-Bootstrapped_Values1(:,1);
var_B=Estimated_Values_1ststep(2)-Estimated_Values_1ststep(1);

pp_test1=var_A-var_B;
pp_test2=sk_A-sk_B;

VAR_TEST=VAR_TEST_A-VAR_TEST_B;
SK_TEST=SK_TEST_A-SK_TEST_B;

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

Estim=[pp_test1;pp_test2];
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')
SK_TEST_A=Bootstrapped_Values1(:,4)-Bootstrapped_Values1(:,3);
sk_A=Estimated_Values_1ststep(4)-Estimated_Values_1ststep(3);
VAR_TEST_A=Bootstrapped_Values1(:,2)-Bootstrapped_Values1(:,1);
var_A=Estimated_Values_1ststep(2)-Estimated_Values_1ststep(1);

load('../Section5/results_Y_T_RECESSIONS')
SK_TEST_B=Bootstrapped_Values1(:,4)-Bootstrapped_Values1(:,3);
sk_B=Estimated_Values_1ststep(4)-Estimated_Values_1ststep(3);
VAR_TEST_B=Bootstrapped_Values1(:,2)-Bootstrapped_Values1(:,1);
var_B=Estimated_Values_1ststep(2)-Estimated_Values_1ststep(1);

pp_test1=var_A-var_B;
pp_test2=sk_A-sk_B;

VAR_TEST=VAR_TEST_A-VAR_TEST_B;
SK_TEST=SK_TEST_A-SK_TEST_B;

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

Estim=[pp_test1;pp_test2];
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_{2}^{η,e}-m_{2}^{η,c}]^{Y}-[m_{2}^{η,e}-m_{2}^{η,c}]^{Y-T}';...
        '[m_{3}^{η,e}-m_{3}^{η,c}]^{Y}-[m_{3}^{η,e}-m_{3}^{η,c}]^{Y-T}';...
        '[m_{2}^{η,e}-m_{2}^{η,c}]^{Y}-[m_{2}^{η,e}-m_{2}^{η,c}]^{T+bn}';...
        '[m_{3}^{η,e}-m_{3}^{η,c}]^{Y}-[m_{3}^{η,e}-m_{3}^{η,c}]^{T+bn}';...
        '[m_{2}^{η,e}-m_{2}^{η,c}]^{Y}-[m_{2}^{η,e}-m_{2}^{η,c}]^{T+bn-T}';...
        '[m_{3}^{η,e}-m_{3}^{η,c}]^{Y}-[m_{3}^{η,e}-m_{3}^{η,c}]^{T+bn-T}'};

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


