%% construction of Table 3 %%
clear all

%% baseline
load result_baseline_3prm

table3(1,1) = size(xmin_u1,2);
table3(2,1) = -fval_u;
table3(3,1) = log(T)*table3(1,1) - 2*(table3(2,1));

% 3-month
table3(4,1) = 0;
table3(5,1) = 0;
table3(6,1) = var_share(3,1); % wL
table3(7,1) = table4_se(1,1); % se_wL
table3(8,1) = var_share(3,2); %wH
table3(9,1) = table4_se(2,1); %se_wH
table3(10,1) = var_share(3,3); %xL
table3(11,1) = table4_se(3,1); %se_xL
table3(12,1) = var_share(3,4); %xH
table3(13,1) = table4_se(4,1); %se_xH
table3(14,1) = table3(6,1)+table3(8,1); %inflows
table3(15,1) = table3(6,1)+table3(10,1); %type L

% 1-year
table3(16,1) = 0;
table3(17,1) = 0;
table3(18,1) = var_share(12,1); % wL
table3(19,1) = table4_se(5,1); % se_wL
table3(20,1) = var_share(12,2); %wH
table3(21,1) = table4_se(6,1); %se_wH
table3(22,1) = var_share(12,3); %xL
table3(23,1) = table4_se(7,1); %se_xL
table3(24,1) = var_share(12,4); %xH
table3(25,1) = table4_se(8,1); %se_xH
table3(26,1) = table3(18,1)+table3(20,1); %inflows
table3(27,1) = table3(18,1)+table3(22,1); %type L

% 2-year
table3(28,1) = 0;
table3(29,1) = 0;
table3(30,1) = var_share(24,1); % wL
table3(31,1) = table4_se(9,1); % se_wL
table3(32,1) = var_share(24,2); %wH
table3(33,1) = table4_se(10,1); %se_wH
table3(34,1) = var_share(24,3); %xL
table3(35,1) = table4_se(11,1); %se_xL
table3(36,1) = var_share(24,4); %xH
table3(37,1) = table4_se(12,1); %se_xH
table3(38,1) = table3(30,1)+table3(32,1); %inflows
table3(39,1) = table3(30,1)+table3(34,1); %type L

clearvars -except table3

%%
load result_hs_3prm

table3(1,2) = size(xmin_u1,2);
table3(2,2) = -fval_u;
table3(3,2) = log(T)*table3(1,2) - 2*(table3(2,2));

% 3-month
table3(4,2) = 0;
table3(5,2) = 0;
table3(6,2) = var_share(3,1); % wL
table3(7,2) = table4_se(1,1); % se_wL
table3(8,2) = var_share(3,2); %wH
table3(9,2) = table4_se(2,1); %se_wH
table3(10,2) = var_share(3,3); %xL
table3(11,2) = table4_se(3,1); %se_xL
table3(12,2) = var_share(3,4); %xH
table3(13,2) = table4_se(4,1); %se_xH
table3(14,2) = table3(6,2)+table3(8,2); %inflows
table3(15,2) = table3(6,2)+table3(10,2); %type L

% 1-year
table3(16,2) = 0;
table3(17,2) = 0;
table3(18,2) = var_share(12,1); % wL
table3(19,2) = table4_se(5,1); % se_wL
table3(20,2) = var_share(12,2); %wH
table3(21,2) = table4_se(6,1); %se_wH
table3(22,2) = var_share(12,3); %xL
table3(23,2) = table4_se(7,1); %se_xL
table3(24,2) = var_share(12,4); %xH
table3(25,2) = table4_se(8,1); %se_xH
table3(26,2) = table3(18,2)+table3(20,2); %inflows
table3(27,2) = table3(18,2)+table3(22,2); %type L

% 2-year
table3(28,2) = 0;
table3(29,2) = 0;
table3(30,2) = var_share(24,1); % wL
table3(31,2) = table4_se(9,1); % se_wL
table3(32,2) = var_share(24,2); %wH
table3(33,2) = table4_se(10,1); %se_wH
table3(34,2) = var_share(24,3); %xL
table3(35,2) = table4_se(11,1); %se_xL
table3(36,2) = var_share(24,4); %xH
table3(37,2) = table4_se(12,1); %se_xH
table3(38,2) = table3(30,2)+table3(32,2); %inflows
table3(39,2) = table3(30,2)+table3(34,2); %type L

clearvars -except table3

%% post 94 data

load result_base_3prm_post94

table3(1,3) = size(xmin_u1,2);
table3(2,3) = -fval_u;
table3(3,3) = log(T)*table3(1,3) - 2*(table3(2,3));

% 3-month
table3(4,3) = 0;
table3(5,3) = 0;
table3(6,3) = var_share(3,1); % wL
table3(7,3) = table4_se(1,1); % se_wL
table3(8,3) = var_share(3,2); %wH
table3(9,3) = table4_se(2,1); %se_wH
table3(10,3) = var_share(3,3); %xL
table3(11,3) = table4_se(3,1); %se_xL
table3(12,3) = var_share(3,4); %xH
table3(13,3) = table4_se(4,1); %se_xH
table3(14,3) = table3(6,3)+table3(8,3); %inflows
table3(15,3) = table3(6,3)+table3(10,3); %type L

% 1-year
table3(16,3) = 0;
table3(17,3) = 0;
table3(18,3) = var_share(12,1); % wL
table3(19,3) = table4_se(5,1); % se_wL
table3(20,3) = var_share(12,2); %wH
table3(21,3) = table4_se(6,1); %se_wH
table3(22,3) = var_share(12,3); %xL
table3(23,3) = table4_se(7,1); %se_xL
table3(24,3) = var_share(12,4); %xH
table3(25,3) = table4_se(8,1); %se_xH
table3(26,3) = table3(18,3)+table3(20,3); %inflows
table3(27,3) = table3(18,3)+table3(22,3); %type L

% 2-year
table3(28,3) = 0;
table3(29,3) = 0;
table3(30,3) = var_share(24,1); % wL
table3(31,3) = table4_se(9,1); % se_wL
table3(32,3) = var_share(24,2); %wH
table3(33,3) = table4_se(10,1); %se_wH
table3(34,3) = var_share(24,3); %xL
table3(35,3) = table4_se(11,1); %se_xL
table3(36,3) = var_share(24,4); %xH
table3(37,3) = table4_se(12,1); %se_xH
table3(38,3) = table3(30,3)+table3(32,3); %inflows
table3(39,3) = table3(30,3)+table3(34,3); %type L

clearvars -except table3

%% unadjusted data

load result_unadj_3prm

table3(1,4) = size(xmin_u1,2);
table3(2,4) = -fval_u;
table3(3,4) = log(T)*table3(1,4) - 2*(table3(2,4));

% 3-month
table3(4,4) = 0;
table3(5,4) = 0;
table3(6,4) = var_share(3,1); % wL
table3(7,4) = table4_se(1,1); % se_wL
table3(8,4) = var_share(3,2); %wH
table3(9,4) = table4_se(2,1); %se_wH
table3(10,4) = var_share(3,3); %xL
table3(11,4) = table4_se(3,1); %se_xL
table3(12,4) = var_share(3,4); %xH
table3(13,4) = table4_se(4,1); %se_xH
table3(14,4) = table3(6,4)+table3(8,4); %inflows
table3(15,4) = table3(6,4)+table3(10,4); %type L

% 1-year
table3(16,4) = 0;
table3(17,4) = 0;
table3(18,4) = var_share(12,1); % wL
table3(19,4) = table4_se(5,1); % se_wL
table3(20,4) = var_share(12,2); %wH
table3(21,4) = table4_se(6,1); %se_wH
table3(22,4) = var_share(12,3); %xL
table3(23,4) = table4_se(7,1); %se_xL
table3(24,4) = var_share(12,4); %xH
table3(25,4) = table4_se(8,1); %se_xH
table3(26,4) = table3(18,4)+table3(20,4); %inflows
table3(27,4) = table3(18,4)+table3(22,4); %type L

% 2-year
table3(28,4) = 0;
table3(29,4) = 0;
table3(30,4) = var_share(24,1); % wL
table3(31,4) = table4_se(9,1); % se_wL
table3(32,4) = var_share(24,2); %wH
table3(33,4) = table4_se(10,1); %se_wH
table3(34,4) = var_share(24,3); %xL
table3(35,4) = table4_se(11,1); %se_xL
table3(36,4) = var_share(24,4); %xH
table3(37,4) = table4_se(12,1); %se_xH
table3(38,4) = table3(30,4)+table3(32,4); %inflows
table3(39,4) = table3(30,4)+table3(34,4); %type L

clearvars -except table3

%% time-varying GDD

load result_base_3prm_rec

table3(1,5) = size(xmin_u1,2);
table3(2,5) = -fval_u;
table3(3,5) = log(T)*table3(1,5) - 2*(table3(2,5));

% 3-month
table3(4,5) = 0;
table3(5,5) = 0;
table3(6,5) = var_share(3,1); % wL
table3(7,5) = table4_se(1,1); % se_wL
table3(8,5) = var_share(3,2); %wH
table3(9,5) = table4_se(2,1); %se_wH
table3(10,5) = var_share(3,3); %xL
table3(11,5) = table4_se(3,1); %se_xL
table3(12,5) = var_share(3,4); %xH
table3(13,5) = table4_se(4,1); %se_xH
table3(14,5) = table3(6,5)+table3(8,5); %inflows
table3(15,5) = table3(6,5)+table3(10,5); %type L

% 1-year
table3(16,5) = 0;
table3(17,5) = 0;
table3(18,5) = var_share(12,1); % wL
table3(19,5) = table4_se(5,1); % se_wL
table3(20,5) = var_share(12,2); %wH
table3(21,5) = table4_se(6,1); %se_wH
table3(22,5) = var_share(12,3); %xL
table3(23,5) = table4_se(7,1); %se_xL
table3(24,5) = var_share(12,4); %xH
table3(25,5) = table4_se(8,1); %se_xH
table3(26,5) = table3(18,5)+table3(20,5); %inflows
table3(27,5) = table3(18,5)+table3(22,5); %type L

% 2-year
table3(28,5) = 0;
table3(29,5) = 0;
table3(30,5) = var_share(24,1); % wL
table3(31,5) = table4_se(9,1); % se_wL
table3(32,5) = var_share(24,2); %wH
table3(33,5) = table4_se(10,1); %se_wH
table3(34,5) = var_share(24,3); %xL
table3(35,5) = table4_se(11,1); %se_xL
table3(36,5) = var_share(24,4); %xH
table3(37,5) = table4_se(12,1); %se_xH
table3(38,5) = table3(30,5)+table3(32,5); %inflows
table3(39,5) = table3(30,5)+table3(34,5); %type L

clearvars -except table3

%% factor model

load result_base_3prm_fc

table3(1,6) = size(xmin_u1,2);
table3(2,6) = -fval_u;
table3(3,6) = log(T)*table3(1,6) - 2*(table3(2,6));

% 3-month
table3(4,6) = var_share(3,1); % factor
table3(5,6) = table4_se(1,1); % se_wL

table3(6,6) = var_share(3,2); % wL
table3(7,6) = table4_se(2,1); % se_wL

table3(8,6) = var_share(3,3); %wH
table3(9,6) = table4_se(3,1); %se_wH

table3(10,6) = var_share(3,4); %xL
table3(11,6) = table4_se(4,1); %se_xL

table3(12,6) = var_share(3,5); %xH
table3(13,6) = table4_se(5,1); %se_xH

table3(14,6) = table3(6,6)+table3(8,6); %inflows
table3(15,6) = table3(6,6)+table3(10,6); %type L

% 1-year
table3(16,6) = var_share(12,1); % wL
table3(17,6) = table4_se(6,1); % se_wL

table3(18,6) = var_share(12,2); % wL
table3(19,6) = table4_se(7,1); % se_wL

table3(20,6) = var_share(12,3); %wH
table3(21,6) = table4_se(8,1); %se_wH

table3(22,6) = var_share(12,4); %xL
table3(23,6) = table4_se(9,1); %se_xL

table3(24,6) = var_share(12,5); %xH
table3(25,6) = table4_se(10,1); %se_xH

table3(26,6) = table3(18,6)+table3(20,6); %inflows
table3(27,6) = table3(18,6)+table3(22,6); %type L

% 2-year
table3(28,6) = var_share(24,1); % wL
table3(29,6) = table4_se(11,1); % se_wL
table3(30,6) = var_share(24,2); % wL
table3(31,6) = table4_se(12,1); % se_wL
table3(32,6) = var_share(24,3); %wH
table3(33,6) = table4_se(13,1); %se_wH
table3(34,6) = var_share(24,4); %xL
table3(35,6) = table4_se(14,1); %se_xL
table3(36,6) = var_share(24,5); %xH
table3(37,6) = table4_se(15,1); %se_xH
table3(38,6) = table3(30,6)+table3(32,6); %inflows
table3(39,6) = table3(30,6)+table3(34,6); %type L

clearvars -except table3

%% weekly frequency

load result_base_3prm_wk

table3(1,7) = size(xmin_u1,2);
table3(2,7) = -fval_u;
table3(3,7) = log(T)*table3(1,7) - 2*(table3(2,7));

% 3-month
table3(4,7) = 0;
table3(5,7) = 0;
table3(6,7) = var_share(3,1); % wL
table3(7,7) = table4_se(1,1); % se_wL
table3(8,7) = var_share(3,2); %wH
table3(9,7) = table4_se(2,1); %se_wH
table3(10,7) = var_share(3,3); %xL
table3(11,7) = table4_se(3,1); %se_xL
table3(12,7) = var_share(3,4); %xH
table3(13,7) = table4_se(4,1); %se_xH
table3(14,7) = table3(6,7)+table3(8,7); %inflows
table3(15,7) = table3(6,7)+table3(10,7); %type L

% 1-year
table3(16,7) = 0;
table3(17,7) = 0;
table3(18,7) = var_share(12,1); % wL
table3(19,7) = table4_se(5,1); % se_wL
table3(20,7) = var_share(12,2); %wH
table3(21,7) = table4_se(6,1); %se_wH
table3(22,7) = var_share(12,3); %xL
table3(23,7) = table4_se(7,1); %se_xL
table3(24,7) = var_share(12,4); %xH
table3(25,7) = table4_se(8,1); %se_xH
table3(26,7) = table3(18,7)+table3(20,7); %inflows
table3(27,7) = table3(18,7)+table3(22,7); %type L

% 2-year
table3(28,7) = 0;
table3(29,7) = 0;
table3(30,7) = var_share(24,1); % wL
table3(31,7) = table4_se(9,1); % se_wL
table3(32,7) = var_share(24,2); %wH
table3(33,7) = table4_se(10,1); %se_wH
table3(34,7) = var_share(24,3); %xL
table3(35,7) = table4_se(11,1); %se_xL
table3(36,7) = var_share(24,4); %xH
table3(37,7) = table4_se(12,1); %se_xH
table3(38,7) = table3(30,7)+table3(32,7); %inflows
table3(39,7) = table3(30,7)+table3(34,7); %type L

clearvars -except table3

save table3
