naffe15 / BVAR_

Empirical macro toolbox
GNU General Public License v3.0
130 stars 76 forks source link

How to add lagged exogenous variables #8

Closed SangJL closed 2 years ago

SangJL commented 2 years ago

Hello! Could you let me know how to add lagged exogenous variables?

For example, y = [ y_1 ; y_2 ; ... ; y_100] w = [ w_1 ; w_2 ; ... ; w_100] And let lags = 2;

Then w(t) = [w_3; ... ; w_100], w(t-1) = [w_2; ... ; w_99], w(t-2) = [w_1; ... ; w_98]

According to HitchhikerGuide_.pdf(7 page), the user supplies z(t) to the toolkit and thus may include in the z(t) not only variables which are contemporaneous to y(t) but also lags, i.e. z(t) = [w(t), w(t-1), w(t-2)].

But thing is that the row length of z(t) is 98 but the row length of y(t) is 100, so I can't put z(t) into y(t) = Phi(L) y(t-1) + Phi0 + Gamma z(t) + u(t).

More importantly, the function rfvar3, which combines endogenous variables and exogenous variables for OLS estimation, uses the following codes:

X = [lagged_endo_var(:,:) exo_var(lags+1,:)]; y = ydata(lags+1,:);

I think I need to add zeros matrix to z(t), that is = z(t) = [ zeros(lags,nvar) ; z(t) ] to match time series sequences.

But codes above are not working! What is wrong with the codes?

-------full code---------------(Note : in this code, I want to use z(t) = [ w(t-1), w(t-2) ])

lags = 3

%create lagged exogenous variables [yyex,exo] = YXB(w,lags,[0 0]); exo = [ zeros(lags,size(exo,2)); exo]; options.controls = exo;

bvar = bvar_(y,lags,options);

naffe15 commented 2 years ago

Hello,

thanks for using the toolbox and for your question.

Assuming 2 lags in the exogenous variables, the best thing to do is to define the matrix of exogenous variables as follows
W =[ w(1), nan, nan; w(2), w(1), nan; w(3), w(2), w(1); w(4), w(3), w(2); .... ]; The matrix W can be created using the function lagX.m. I have updated 'example_6_VARX.m' to account for lagged variables. This works when # of lags of the exogenous variables <= # of lags in the VAR part. When this is not the case, say one lag in the VAR part and two lags for the exogenous variables, then you need to remove the first raw of 'y' (the endogenous variables of the VAR) and the first raw of 'W' (the matrix of exogenous variables).

SangJL commented 2 years ago

It looks working! Thank you!