I am currently working with Dynare 3.65 with a model where I am using some matrix algebra in the model section, e.g. I write:
A = rho 0 0 ; 1 0 0 ; 0 0 rho ];
B = eye(3);
C = A*B;
and then I use specific elements of matrix C as coefficients for some variables in the model section.
This code does not work in dynare 4 anymore, as it seems that I cannot declare matrices and do some algebra with the matrices. Is there a trick/possibility to enter matrices in dynare 4?
Thank you very much in advance for your support.
No sorry, this is not possible in Dynare 4.
You need to write your algebra in mono-dimensional form.
There is a trick to incorporate matrix algebra in the model section; in fact one can use any Matlab function.
Using the steps outlined in Steady state file one can manipulate the model_steadystate.m file to incorporate steady state values. Following this advise one can use the parameters of the model to do any kind of Matlab calculations. In my case I do some matrix algebra and define the elements of interest of some matrix as new variables, e.g. A23=A(2,3) where A is a matrix calculated in the model_steadystate.m file. In my mod-file I define A23 to be a parameter. I can then use A23 as a coefficient for a variable in the model section.
Would anyone be able to elaborate on this? I would like to run a model with some matrices in Dynare but cannot see how to do it.
Thank you for any help!
Please have a look at github.com/JohannesPfeifer/DSGE_mod/tree/master/Chari_et_al_2007 where I use a steady state file to do matrix computations and then assign the results back to paramaters of the model
Thank you for this update, I see Dynare allows us to use matrices in calculations of steady states which will be very uesful but I would also like to have matrices in my model itself.
My model equations have been completed with matrix algebra, do you have any advice on how to implement these into the model of Dynare?
I have started to rewrite the model using (many) “for” loop macro-expressions in Dynare which would be fine if it weren’t for an inverted matrix which appears in one of my model equations. I am about to start translating some manual code to invert a matrix into Dynare macro-expressions but any advice on better ways to achieve this result would be much appreciated!
This is a current limitation of Dynare. You cannot use matrices in the model block and I don’t see a good way around this. Again, you would have to do the inversion in the steady state file and pass the result back.
Sadly, the matrix I would like to include in the model is made up of endogenous variables so its elements will be changing as the shock hits the system so I don’t think I will be able to use the steady state file as you suggest, though do correct me if I am wrong!
In any case, I will find a workaround by rewriting the model in mono-dimensional form and using macro-expressions.
This sounds like a case where you need to use an external function to capture the derivatives correctly.