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_EXP_A=Bootstrapped_Values2(:,2);
var_E_A=Estimated_Values_2ndstep(2);
VAR_CONTR_A=Bootstrapped_Values2(:,1);
var_C_A=Estimated_Values_2ndstep(1);


load('../Section5/results_Y_N_RECESSIONS')

VAR_EXP_B=Bootstrapped_Values2(:,2);
var_E_B=Estimated_Values_2ndstep(2);
VAR_CONTR_B=Bootstrapped_Values2(:,1);
var_C_B=Estimated_Values_2ndstep(1);

pp_test1=var_E_A-var_E_B;
pp_test2=var_C_A-var_C_B;

VAR_EXP_TEST=VAR_EXP_A-VAR_EXP_B;
VAR_CONTR_TEST=VAR_CONTR_A-VAR_CONTR_B;

CI_perc = prctile([VAR_EXP_TEST VAR_CONTR_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')
VAR_EXP_A=Bootstrapped_Values2(:,2);
var_E_A=Estimated_Values_2ndstep(2);
VAR_CONTR_A=Bootstrapped_Values2(:,1);
var_C_A=Estimated_Values_2ndstep(1);

load('../Section5/results_Y_B_RECESSIONS')
VAR_EXP_B=Bootstrapped_Values2(:,2);
var_E_B=Estimated_Values_2ndstep(2);
VAR_CONTR_B=Bootstrapped_Values2(:,1);
var_C_B=Estimated_Values_2ndstep(1);


pp_test1=var_E_A-var_E_B;
pp_test2=var_C_A-var_C_B;

VAR_EXP_TEST=VAR_EXP_A-VAR_EXP_B;
VAR_CONTR_TEST=VAR_CONTR_A-VAR_CONTR_B;

CI_perc = prctile([VAR_EXP_TEST;VAR_CONTR_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')
VAR_EXP_A=Bootstrapped_Values2(:,2);
var_E_A=Estimated_Values_2ndstep(2);
VAR_CONTR_A=Bootstrapped_Values2(:,1);
var_C_A=Estimated_Values_2ndstep(1);

load('../Section5/results_Y_T_RECESSIONS')
VAR_EXP_B=Bootstrapped_Values2(:,2);
var_E_B=Estimated_Values_2ndstep(2);
VAR_CONTR_B=Bootstrapped_Values2(:,1);
var_C_B=Estimated_Values_2ndstep(1);

pp_test1=var_E_A-var_E_B;
pp_test2=var_C_A-var_C_B;

VAR_EXP_TEST=VAR_EXP_A-VAR_EXP_B;
VAR_CONTR_TEST=VAR_CONTR_A-VAR_CONTR_B;

CI_perc = prctile([VAR_EXP_TEST;VAR_CONTR_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

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

TABLE_5_tau_4 = table(round(TEST,4),significance,'RowNames',name);
disp('Table 5 (tau=4): Policy effects on persistent component')
disp(TABLE_5_tau_4)

