%% Table 11
%% Date: 11/02/2020
%% Relation between lagged rr and bf to future intervention with sub-sample analysis
cd(ini.dirs.code)
%% Initialize all data matrix
load ccydates; 
T=size(ccydates,1);
%% intervention
load intervention; load interventiondates;
idx=ismember(ccydates,interventiondates);
int=NaN(T,1);
int(idx)=intervention;

load lagliborchange;load lagtelborchange;

%% dates

%% RR & BF
load('lagrr'); load('lagbf1'); load('lagbf2');
load('bf25lag');load('bf10lag');load('rr25lag');load('rr10lag');
%% CDS
load('lagcds')

%% ccys
load ilsnyccy;
load ilslondonccy;
load NEERny;

%% Change in NEER
load lagNEER1
load lagNEER2
load lagNEER5
load lagNEER60
%load lagNEER3

%% Flows
load laginstflows
load lagforeignflows

res=NaN(8,6);
idx=find(ccydates==datenum('01/02/2016','dd/mm/yyyy')); %% beginning of sample
idx1=find(ccydates==datenum('31/01/2020','dd/mm/yyyy'));


for j=1:6 %% run on all BF and all RR
[coeff,tstat,r,n]=fastnw(int(idx:idx1)/1000,[lagNEER1(idx:idx1,2),lagNEER5(idx:idx1,3),lagNEER60(idx:idx1,2),lagcds(idx:idx1,2),lagforeignflows(idx:idx1,2)+laginstflows(idx:idx1,2),lagtelborchange(idx:idx1,2),lagliborchange(idx:idx1,2),.5*(rr25lag(idx:idx1,6+j)+rr10lag(idx:idx1,6+j)),.5*(bf25lag(idx:idx1,6+j)+bf10lag(idx:idx1,6+j))],1,60); %% divide int by 1000.

%% intercept
res(1,j)=coeff(1);
res(2,j)=tstat(1);

%% rr
res(3,j)=coeff(end-1);
res(4,j)=tstat(end-1);
%% bf
res(5,j)=coeff(end);
res(6,j)=tstat(end);
res(end,j)=r;
end

