LaTeX output of model equations in exp form


#1

Dear all,

The model I work with now has log-linearized variables ( variables defined in exp(.) format, say if the model equation is x = y+ z, then in the model block it is exp(x) = exp(y)+exp(z) ).

I was wondering if there is a way for Dynare to output the model equations in TeX format substituting the ‘‘exp(‘variable’)’’ form to the original variable. (for example, if I want to output the equation above, I can still get x = y+z, not exp(x) = exp(y)+exp(z) ).

I know manually substitution is one way to go, but just wondering if Dynare has an automated way already.

Thank you.


#2

Hi, I do not think that there is an option in Dynare to do the substitution automatically. But you can do it using matlab’s regular expressions. I would do something like:

write_latex_original_model;

// Loaad content of the TeX file generated by dynare.
texContent = fileread('substitution_original_content.tex');

// Remove exp functions.
expression = 'exp\\left\(\{(?<EXPRESSION>((\w*_\{t\})|(\\\w*_\{t\})|(\w*_\{t-\d\})|(\\\w*_\{t-\d\})|(\w*_\{t\+\d\})|(\\\w*_\{t\+\d\})))\}\\right)';
texContent = regexprep(texContent, expression, '$1');

// Update the original TeX file.
fid = fopen('substitution_original_content.tex','w');
fwrite(fid, texContent);
fclose(fid);

after the model declaration in the mod file. Note that it will replace all the terms of the form exp(X) by X, even if X is not an endogenous variable. You may need to adapt the value of expression (because I tested this code snippet only on a simple example), just look at the matlab documentation about regular expressions.

Best,
Stéphane.


#3

Dear Stéphane,

This is absolutely gorgeous. Thanks for the advice!

Regards,
TS