Page 1 of 1

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

PostPosted: Tue Feb 21, 2012 3:57 pm
by joasi
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:
Code: Select all
L^mu*P=W*C^(-phi)

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

2. 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:
Code: Select all
[exp(lL)^mu]*exp(lP)=exp(lW)*[exp(lC)^(-phi)]

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.

3. 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:
Code: Select all
mu * l_hat + p_hat = w_hat – phi * c_hat
C_bar + C_bar * c_hat = …

Does Dynare understand that c_hat means (log(c)-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

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Tue Feb 21, 2012 10:44 pm
by jpfeifer
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(c)-log(C_bar)) in any fundamental sense. c_hat is only a variable name that you assigned to (log(c)-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.

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Thu Feb 23, 2012 10:58 pm
by joasi
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.

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Fri Feb 24, 2012 8:14 am
by jpfeifer
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.

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Sun May 04, 2014 12:31 pm
by 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! :) )

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Tue May 06, 2014 1:05 pm
by lah89
lah89 wrote: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! :) )


+ 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.

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Wed May 07, 2014 9:58 am
by jpfeifer
Please see Pfeifer(2013): "A Guide to Specifying Observation Equations for the Estimation of DSGE Models" https://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;
Code: Select all
var y yy;
model;

yy=log(y)
end;

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Wed May 14, 2014 3:43 pm
by lah89
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
Code: Select all
var y_tilde c_tilde k_tilde z R_tilde Pi_tilde;
only instead of
Code: Select all
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 ?

;)

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Wed May 14, 2014 5:21 pm
by jpfeifer
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)

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Sun May 18, 2014 11:47 am
by lah89
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:
Code: Select all
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:
Code: Select all
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?

Re: Non-linear vs. exp() vs. log-linearized models

PostPosted: Sun May 18, 2014 1:50 pm
by jpfeifer
Yes. Looks correct.