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

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

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

Postby joasi » Tue Feb 21, 2012 3:57 pm

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
joasi
 
Posts: 5
Joined: Tue Jan 17, 2012 11:45 am
Location: Singapore

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

Postby jpfeifer » Tue Feb 21, 2012 10:44 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

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

Postby joasi » Thu Feb 23, 2012 10:58 pm

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.
joasi
 
Posts: 5
Joined: Tue Jan 17, 2012 11:45 am
Location: Singapore

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

Postby jpfeifer » Fri Feb 24, 2012 8:14 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

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

Postby lah89 » Sun May 04, 2014 12:31 pm

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! :) )
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

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

Postby lah89 » Tue May 06, 2014 1:05 pm

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.
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

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

Postby jpfeifer » Wed May 07, 2014 9:58 am

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;
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

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

Postby lah89 » Wed May 14, 2014 3:43 pm

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 ?

;)
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

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

Postby jpfeifer » Wed May 14, 2014 5:21 pm

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)
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

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

Postby lah89 » Sun May 18, 2014 11:47 am

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?
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

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

Postby jpfeifer » Sun May 18, 2014 1:50 pm

Yes. Looks correct.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 9 guests