Questions about Macro Language Related to Vectors

Hello everyone,

I’m currently facing a few issues when using macro-language in Dynare. I would appreciate any help or insights!

1. How to Access Elements in a MATLAB Vector Using Macro Language?

I tried to extract an element from a MATLAB vector using macro-language, but it resulted in an error. Here’s what I attempted:

xx = [1; 2; 3];
@define x1 = xx(1)

This approach did not work as expected. How can I correctly access the first element of the xx vector within a macro definition?

2. Accessing Elements from a Macro-Defined Vector

In another case, I defined a vector directly in the macro language and wanted to retrieve its first element. The following code also produced an error:

@define xx = [1, 2, 3]
@define x1 = @{xx(1)}

3. Error When Using Macro-Defined Vectors in the shocks Block

I’m encountering a syntax error when trying to define a shocks block using macro-defined vectors. Here’s the code I wrote:

@#define xx = [3.1, 3.5]
@#define leg = length(xx)

shocks;
var x;
periods 1:@{leg};
values @{xx};
end;

However, this results in the following error:

syntax error, unexpected '['

Thank you in advance for your help!

What is the ultimate goal you are trying to achieve?

  1. The is not a use-case that is supported. At runtime of the macroprocessor, the content of the Matlab variable is not yet known. Depending on what you are trying to do, there may be other ways to implement it.
  2. A correct code would be
@#define xx = [1, 2, 3]
@#define x1 = (real)xx[1]
@{x1}
  1. That is also not easily feasible, but there is a straigthforward workaround by calling the mod-file with a Matlab script.
1 Like

Dear Professor,

Thank you once again for your help.

In fact, I am currently trying to perform a perfect foresight simulation of an RBC model using an exogenous TFP sequence, possibly with a trend.

I would like to set the steady state in initval to correspond to the initial value of the TFP sequence, use the middle part of the sequence in shocks, and set the steady state in endval to the final value of the TFP sequence.

I’ve managed to run the simulation by setting everything manually, but I’m hoping to write the code more elegantly using the macro language.

Now I understand this is much complicated than I think. But still, I appreciate your kindly help!

That very much sounds like a case where you should directly manipulate oo_.endo_simul and oo_.exo_simul before calling perfect_foresight_solver.