# Non-linear vs. exp() vs. log-linearized models

Dear all,

I am confused by the different ways of proceeding to solve a DSGE model (a small open economy) in Dynare and to calculate the steady state.

1. The first way by which I try to solve the model is by inputting my non-linear equations into a .mod file and** letting Dynare linearize** them. An example equation:

I calculate the steady state for this model analytically. Then I initialize ss values using the initval command.

1. The second way by which I tried to solve the model is by letting Dynare log-linearize it. I enclose each variable in exp(). Now, the same equation as above becomes as follows in the .mod file:

I use the same steady state as in point 1, but in the initval block I take the log() of each ss variable to initialize.
What do I do when the steady-state of the non-linear model contain zeros? I canât take log(0) in the initval block of the exp-model.

1. Some of you recommend log-linearizing by hand. I understand that in simple cases the steady states values are equal to zeros, but as I have sums present in my equations, in my log-linearized equations I will have both steady state variables different from zero (denoted as a capital letters with âbarâ) and log-linearized variables (denoted as small letters with âhatâ).
Example equations:

```mu * l_hat + p_hat = w_hat â phi * c_hat C_bar + C_bar * c_hat = âŠ```
**Does Dynare understand that c_hat means (logÂ©-log(C_bar))? Or should I explicitly replace all _hat variables by the difference in logs?
How do I calculate the steady state of such a log-linearized model?
**

Thanks

Regarding 2: you cannot take logs of variables whose steady state is 0. Hence, putting them in exp() is not possible. The same by the way applies to variables with negative steady states like e.g. the net foreign bond position of an indebted country. Usually you just leave those variables without the exp(), i.e. only linearized.
Regarding 3: Log-linearizing the model by hand only shifts the steady state computation problem to setting parameters like Cbar in your example. For those you still have to manually compute the steady state value. That is, you need the steady state of consumption as a function of the deep parameters to set Cbar before the model block. Note also that shifting the steady state computation into the parameters complicates things in estimation as you have to reset all parameters for each draw of deep parameters. This is usually more cumbersome in Dynare than providing values for endogeneous variables.

Dynare does not âunderstandâ that c_hat means (logÂ©-log(C_bar)) in any fundamental sense. c_hat is only a variable name that you assigned to (logÂ©-log(C_bar)) after log-linearization. Hence, while there is no concept of âunderstandingâ at work, c_hat actually has the interpretation as percentage deviations from steady state as you desire (if your manual log-linearization is correct).

Note also that the additive constants like Cbar can be subtracted from both sides and thus drop out.

Thank you very much for your advice. Leaving variables that are 0 in steady state without exp() helped, and now I am confronted with âInput to SVD must not contain NaN or Inf.â, or âMJDGGES returns the following error code: 7â. I believe that this is due to a division by zero in the calculation of the Jacobian value at the steady state, so I am working on another steady-state, calculated analytically to avoid zeros.

First of all, I would recommend to use Matlab (not Dynare) to check the computation of your steady state initial values and your parameters (just execute the statements in the mod-file using F9). Sometimes the order of declaration is incorrect and some parameters evaluate to NaN or Inf.

So to sum up, how do I go from non-linear levels (command: model;) to logs-deviations then ?
a) in a stochastic setup:
just replace yy = log(y)
and rewrite within the equations exp(yy) instead of y
and keep the model; command because with stoch_simul Dynare is automatically linearizing the model

b) in a deterministic setup:
replace yy = y - y_ss for all endogenous variables,
then replace again yyy=log(yy)
then use model(linear);
and within the equations you write exp(yyy) ?

(could someone please confirm/correct? Thanks! )

[quote=âlah89â]So to sum up, how do I go from non-linear levels (command: model;) to logs-deviations then ?
a) in a stochastic setup:
just replace yy = log(y)
and rewrite within the equations exp(yy) instead of y
and keep the model; command because with stoch_simul Dynare is automatically linearizing the model

b) in a deterministic setup:
replace yy = y - y_ss for all endogenous variables,
then replace again yyy=log(yy)
then use model(linear);
and within the equations you write exp(yyy) ?

(could someone please confirm/correct? Thanks! )[/quote]

• for example in case a): if I declare y as an endogenous variable and then use #yy=log(y) within the model block, I get an error using exp(yy(+1)) since I cannt add leads/laggs to local variables. So where/how to declare yy=log(y) then? Thanks.

Please see Pfeifer(2013): âA Guide to Specifying Observation Equations for the Estimation of DSGE Modelsâ sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf on how to use variable substitution. In the recent Dynare unstable version you can also use the loglinear option of stoch_simul.

You cannot use model-local variables (the ones with the pound operator) to define new variables. Rather, just define a new variable yy that is the log version of your original version. You can basically just append the logs to the non-logged model;

``````var y yy;
model;

yy=log(y)
end;``````

thanks!

I think what confuses most people around here is whether to a) simply replace y by exp(y) or to b) define yy= log(y) and then replace y by exp(yy) in your code.

From Listing 6 of your paper, I see that you dont actually declare yy but rather redefine the variables âin your headâ and declare

`var y_tilde c_tilde k_tilde z R_tilde Pi_tilde; `only instead of `var y c k R Pi y_tilde c_tilde k_tilde z R_tilde Pi_tilde;` (i.e. chose a) ).

The main part that changes is thus only the interpretation which differs because of how you redefined the variables âin your headâ, right ?

1 Like

In the version in my paper, I redefined the variables âin my headâ.

My alternative suggestion had nothing to do with the paper, however. It was to leave the model completely unaltered (without any exp) and then simply add a new additional variable yy=log(y). This yy now has the same interpretation as the y when you replaced the original y by exp(y) (which you donât do in this case)

ok, thank you!
here is what I did now:

My aim is to have the IRFs shown in %-deviations from ss (and not in absolute deviations from ss as under a simple linearized model), which is why I want Dynare to loglinearize the model.
I followed your Listing6 - example:

before:

```var y pi ...; model; // (non-linear equations) y = ...; ...pi = ...; end; ... steady_state_model; y = y_ss; ... end; ... stoch_simul; ```
â> Dynare linearizes, i.e. IRFs plotted show absolute deviations from ss.
My steady state value shown for y = 1.0074

now I replace the original variables by what I think of as their logs, i.e. âLy=log(y)â, but I dont define this anywhere in my mod-file:

```var Ly Lpi ...; model; // (non-linear equations) exp(Ly) = ...; ...exp(Lpi) = ...; end; ... steady_state_model; Ly = log(y_ss); ... end; ... stoch_simul; ```
â> Dynare loglinearizes, i.e. IRFs have to be interpreted as %-deviations from SS
My steady state value shown for Ly = 0.0073897 (where exp(0.0073897)= 1.0074)

Did I get it right?

Yes. Looks correct.