Page 1 of 1

matrices in dynare 3 are not recognized/processed in dynare4

PostPosted: Fri Feb 19, 2010 2:13 pm
by patrickH
Hi,

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.
Best,
Patrick

Re: matrices in dynare 3 are not recognized/processed in dynare4

PostPosted: Mon Feb 22, 2010 3:48 pm
by SébastienVillemot
No sorry, this is not possible in Dynare 4.

You need to write your algebra in mono-dimensional form.

Best

Re: matrices in dynare 3 are not recognized/processed in dynare4

PostPosted: Mon Mar 01, 2010 9:14 am
by patrickH
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 viewtopic.php?f=1&t=1834 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.

Patrick

Re: matrices in dynare 3 are not recognized/processed in dyn

PostPosted: Tue Mar 08, 2016 3:32 pm
by timjackson
Hi,

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!

Best,

Tim

Re: matrices in dynare 3 are not recognized/processed in dyn

PostPosted: Thu Mar 10, 2016 10:52 am
by jpfeifer
Please have a look at https://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

Re: matrices in dynare 3 are not recognized/processed in dyn

PostPosted: Tue Apr 05, 2016 2:03 pm
by timjackson
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!

Thank you,

Tim

Re: matrices in dynare 3 are not recognized/processed in dyn

PostPosted: Tue Apr 05, 2016 7:32 pm
by jpfeifer
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.

Re: matrices in dynare 3 are not recognized/processed in dyn

PostPosted: Tue Apr 05, 2016 9:01 pm
by timjackson
Thank you.

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.

Re: matrices in dynare 3 are not recognized/processed in dyn

PostPosted: Wed Apr 06, 2016 7:54 am
by jpfeifer
This sounds like a case where you need to use an external function to capture the derivatives correctly.