steady state in log-linear system

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.

steady state in log-linear system

Postby fuyangzhao » Thu Oct 20, 2016 2:01 pm

Hi all,

I'm working on a system of log-linear equations. As we know, steady state values of endogenous variable, (y_t-y)/y, is not needed in log-linear system, since they all zeros.

However, the coefficients of those linear equations usually depend on the steady state of the endogenous variables, y, not (y_t-y)/y. So I still need to compute the steady state values of y, except that y is declared as a parameter in .mod file.

My problem is that my equation system is too complicated and I couldn' t solve for analytically y from that nonlinear equation system. So I wonder if it is possible to use fsolve in .m file, and name the file as FILENAME_steadystate.m....FILENAME_steadystate.m is typically used to compute the steady state of endogenous variable, (y_t-y)/y. Can it be used to compute the parameter, y?

BTW, one may question why I don't solve y in an isolate .m file. The reason is that y depends on various parameters, which are undetermined yet since I want to estimate them with Bayesian method.

...Or, could the command
Code: Select all
external_function (OPTIONS. . .);
solve my problem?

Is there any examply I can refer to?
fuyangzhao
 
Posts: 48
Joined: Thu Dec 10, 2015 1:20 pm

Re: steady state in log-linear system

Postby jpfeifer » Thu Oct 20, 2016 3:15 pm

Use a steady_state file as in the NK_baseline.mod in the Dynare examples folder. That file is used to recompute the labor disutility parameter in every iteration. Alternatively, you can call fsolve within a steady_state_model-block as in the example3.mod. In that case, setting the parameter is the only purpose of the steady_state_model-block.
------------
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: steady state in log-linear system

Postby fuyangzhao » Thu Oct 20, 2016 4:37 pm

jpfeifer wrote:Use a steady_state file as in the NK_baseline.mod in the Dynare examples folder. That file is used to recompute the labor disutility parameter in every iteration. Alternatively, you can call fsolve within a steady_state_model-block as in the example3.mod. In that case, setting the parameter is the only purpose of the steady_state_model-block.

Thank you Professor!
As I can see, NK_baseline_steadystate.m takes the value of varpsi (the labor disutility parameter) as given...And varpsi is given in NK_baseline.mod:
Code: Select all
//Estimated parameters, taken from FV(2010), Table 3, p. 38, median estimate parameters

betta =0.998;
h=0.97;
varpsi =8.92;
gammma = 1.17;
kappa =9.51;
alppha =0.21;

thetap =0.82;
chi = 0.63;
thetaw =0.68;
chiw =0.62;
gammmaR =0.77;
gammmay =0.19;

gammmaPI =1.29;
PIbar = 1.01;
rhod  = 0.12;
rhophi = 0.93;
sigma_A = -3.97;
sigma_d = -1.51;

sigma_phi =-2.36;
sigma_mu =-5.43;
sigma_m  =-5.85;
Lambdamu=3.4e-3;
LambdaA = 2.8e-3;

LambdaYd= (LambdaA+alppha*Lambdamu)/(1-alppha);


However, in the following note, you wrote that
Code: Select all
/*
The following parameters are set in the steady state file as they depend on other
deep parameters that were estimated in the original study. Setting them in the
steady state file means they are updated for every parameter draw in the MCMC
algorithm, while the parameters initialized here are only set once for the initial
values of the parameters they depend on:

gammma1 as it depends on LambdaA, alppha, Lambdamu, betta, and delta
Rbar =0 as it depends on PI, LambdaA, alppha, Lambdamu, and betta
Lambdax
*/

So, maybe you have mistaken Rbar and gammma1 as varpsi?
fuyangzhao
 
Posts: 48
Joined: Thu Dec 10, 2015 1:20 pm

Re: steady state in log-linear system

Postby jpfeifer » Thu Oct 20, 2016 5:39 pm

Yes, you are right. I confused this with a different mod-file, but the procedure would be the same as for Rbar and gammma1.
------------
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: steady state in log-linear system

Postby fuyangzhao » Fri Oct 21, 2016 3:25 am

jpfeifer wrote:Yes, you are right. I confused this with a different mod-file, but the procedure would be the same as for Rbar and gammma1.

Thanks for your quick reply!

Based on NK_baseline.mod, I wrote a simple test file in which there are only two endogeneous variables, the model is linear, and two parameters (Rbar gamma1) are solved for in the steady state file.
tri_steadystate.m
(3.02 KiB) Downloaded 57 times
tri.mod
(2.76 KiB) Downloaded 66 times


However, when I run the mod file, it reports
Attempt to execute SCRIPT tri_steadystate as a function:
C:\Users\ASUS\Desktop\tri_steadystate.m

Error in evaluate_steady_state_file (line 49)
[ys,check] = h_steadystate(ys_init, exo_ss);

Error in evaluate_steady_state (line 58)
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ...

Error in steady_ (line 54)
[steady_state,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck);
Error in steady (line 81)
[steady_state,M_.params,info] = steady_(M_,options_,oo_);

Error in tri (line 231)
steady;

Error in dynare (line 180)
evalin('base',fname) ;


I didn't write tri_steadystate.m as a function. In NK_baseline_steadystate.m, NK_baseline_steadystate(ys,exo) is a function of vector of initial values for the steady state of the endogenous variables and vector of values for the exogenous variables. However, in my log-linearized system, there is no initial values for the steady state of the endogenous variables.

Anyway, after I changed tri_steadystate.m as a function.
tri.mod
(2.76 KiB) Downloaded 66 times
It reports the following:
Error in tri_steadystate (line 3)
global M_

Output argument "check" (and maybe others) not assigned during call to "C:\Users\ASUS\Desktop\tri_steadystate.m>tri_steadystate".

Error in evaluate_steady_state_file (line 49)
[ys,check] = h_steadystate(ys_init, exo_ss);

Error in evaluate_steady_state (line 58)
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ...

Error in steady_ (line 54)
[steady_state,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck);
Error in steady (line 81)
[steady_state,M_.params,info] = steady_(M_,options_,oo_);

Error in tri (line 231)
steady;

Error in dynare (line 180)
evalin('base',fname) ;


I do not understand...How do I modify tri_steadystate.m?

Thank again!
Attachments
tri1_steadystate.m
(3.3 KiB) Downloaded 49 times
fuyangzhao
 
Posts: 48
Joined: Thu Dec 10, 2015 1:20 pm

Re: steady state in log-linear system

Postby jpfeifer » Fri Oct 21, 2016 7:00 am

Use the proper functional form and set the check indicator to 1. It is also no true that you do not have steady state values for the endogenous variables. Rather, these values are 0. Because Dynare by default takes 0 as the initial value, the 0 is passed to the steadystate-file and, if you do not alter it, passed back again. For a linear model that works.
Attachments
tri_steadystate.m
(3.3 KiB) Downloaded 64 times
------------
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: steady state in log-linear system

Postby Cfarias » Sat Nov 12, 2016 6:33 pm

Hello Professor,

I'm having the same problem. I'm trying to replicate an exercise model using the steady state file and i don't succeed. As the model is written in log-linear, it's function of steady state values of the endogenous variables. So when i run the mod file i get an error telling "Unknown symbol: Rss", where Rss is some steady state variable. I used the NK_baseline code to do the task and i still can't do the exercise. I read some other topics here in the dynare discussion forum and the closest to my problem was this post.
Attachments
teste_steadystate.m
(1.64 KiB) Downloaded 44 times
teste.mod
(1.05 KiB) Downloaded 47 times
Cfarias
 
Posts: 11
Joined: Sat Nov 12, 2016 6:21 pm

Re: steady state in log-linear system

Postby jpfeifer » Sun Nov 13, 2016 2:28 pm

In your model, there is no point for a steady state file. The variables all have mean 0 as they are percentage deviations from trend. What you need are the levels of the original variables before loglinearization. But those are parameters/expressions in the model that can easily be handled with model-local variables.
Delete the steadystate file and use
Code: Select all
var Y I C R K W L A;

varexo e;

parameters sigma phi alpha beta delta rhoa;

sigma = 2;
phi = 1.5;
alpha = 0.35;
beta = 0.985;
delta = 0.025;
rhoa = 0.95;


model(linear);
#Ass = 1;
#Pss = 1;
#Rss = Pss*((1/beta) - (1-delta));
#Wss = (1-alpha)*(Pss^(1/(1 - alpha))*((alpha/Rss)*(alpha/(1-alpha))));
#Yss = ((Rss/(Rss - delta*alpha))^(sigma/(sigma + phi)))*(((1 - alpha)^(-phi))*((Wss/Pss)^(1+phi)))^(1/(sigma+phi));
#Kss = alpha*(Yss/Rss/Pss);
#Iss = delta*Kss;
#Css = Yss - Iss;
#Lss = (1-alpha)*(Yss/Wss/Pss);

//1. Labor Supply:
sigma*C + phi*L = W;

//2. Euler Equation:
(sigma/beta)*(C(+1) - C) = Rss*R(+1);

//3. Law of motion of capital:
K = (1 - delta)*K(-1) + delta*I;

//4. Production Function:
Y = A + alpha*K(-1) + (1 - alpha)*L;

//5 Capital Demand:
R = Y - K(-1);

//6. Labor Demand:
W = Y - L;

// 7. Market Clearing:
Yss*Y = Css*C + Iss*I;

// 8. Exogenous Process
A = rhoa*A(-1) + e;
end;


// Steady state calculation:
steady;

// Check conditions of the system:
check;

// shock of the system:
shocks;
var e;
stderr 0.01;
end;

// Simulation:
stoch_simul;
------------
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: steady state in log-linear system

Postby Cfarias » Mon Nov 14, 2016 2:04 pm

Thank you Professor., now it did worked.
After that I tried to use the function fsolve function within this model-local variable and and octave reported the following error: "character unrecognized by lexer".
I just changed slightly the code:

Code: Select all
#Ass = 1;
#Pss = 1;
#Rss = Pss*((1/beta) - (1-delta));
#Wss = (1-alpha)*(Pss^(1/(1 - alpha)))*((alpha/Rss)^(alpha/(1-alpha)));
#Yss = ((Rss/(Rss - delta*alpha))^(sigma/(sigma + phi)))*(((Wss/Pss)*((Wss/Pss/(1-alpha))^phi))^(1/(sigma+phi)));
#x = fsolve(@F, [1;1], optimset('Maxiter', 5000));
#Kss = x(1);
#Iss = x(2);
#Css = Yss - Iss;
#Lss = (1-alpha)*(Yss/Wss/Pss);


and the F.m function was pretty standard:
Code: Select all
 function y = F(x)

Kss = x(1);
Iss = x(2);

y(1) = Kss - alpha*(Yss/Rss/Pss);
y(2) = Iss - delta*Kss;

Last edited by Cfarias on Tue Nov 15, 2016 12:24 pm, edited 1 time in total.
Cfarias
 
Posts: 11
Joined: Sat Nov 12, 2016 6:21 pm

Re: steady state in log-linear system

Postby jpfeifer » Mon Nov 14, 2016 5:03 pm

That won't work this way. You cannot call solvers in a model-local variable. What exactly are you trying to achieve? Fo the current problem there is an analytical solution.
------------
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: steady state in log-linear system

Postby Cfarias » Mon Nov 14, 2016 5:43 pm

I'm trying to perform the function fsolve in my own DSGE model. In my exercise, i don't have an analytical solution for every endogenous variable in the steady state. So I'm learning with a simple model in order to apply in the model i'm working on.
I used the NK_baseline where there is a fsolve in the steady state file. That's why a wrote one for this simple model but i didn't succeed to apply it.
Cfarias
 
Posts: 11
Joined: Sat Nov 12, 2016 6:21 pm

Re: steady state in log-linear system

Postby jpfeifer » Tue Nov 15, 2016 9:11 pm

Why then don't you follow the example3.mod in the Dynare examples folder? Your problem in the current setup comes from trying to compute the levels of variables in a loglinearized model. In that case, you need to clearly distinguish between the parameters that depend on the levels of the original variables and the actual variables in the model. The former need to be defined as actual parameters and are assigned their value in the steady state file. But when doing so, you must not forget that you still need to assign the steady state of the actual variables in your model, which are 0.
------------
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: steady state in log-linear system

Postby Cfarias » Wed Nov 16, 2016 8:46 pm

Thank You very much Professor. I have two issues:
First, i followed the example3.mod for my "training" model (teste.mod) and even not using a solver, dynare reported an error: 'The steadystate file did not compute the steady state.'


Second, my real problem is that the model that i'm working on has some variables (4 variables) that don't have analytical solution in the steady state and have to be solved numerically. I'm uploading the .mod file where the model is log-linearized and two.m files (f.m is the "steady state file" and F.m is the function to be called by the solver).
In these files, the parameters have values borrowed from the literature. The reason to do that is to just test if the code is right. However, in the paper some of these parameters will be estimated using Bayesian method, while other will be calibrated and i still have not figured out how to apply fsolve to a sytem of 4 nonlinear equations inside the .mod file or using a steady_state file. Both the NK_baseline.mod and example3.mod used fsolve for one variable.
Attachments
teste.mod
Training model
(1.65 KiB) Downloaded 45 times
F.m
(1.65 KiB) Downloaded 47 times
f.m
(2.52 KiB) Downloaded 43 times
master.mod
(6.37 KiB) Downloaded 42 times
Cfarias
 
Posts: 11
Joined: Sat Nov 12, 2016 6:21 pm

Re: steady state in log-linear system

Postby jpfeifer » Fri Nov 18, 2016 10:14 am

The most important thing is to make sure your steady state computations are correct. You have
Code: Select all
ln(A) = rhoa*ln(A(-1)) + (1-rhoa) +  e;

Without the (1-rhoa) part, this equation has steady state 1. But the additional constant you put it makes that not the steady state.
Similarly,
Code: Select all
(C(+1)/C)^sigma = beta*((1-delta) + R(+1)/R);

does not look correct. In steady state, it reads
Code: Select all
1 = beta*((1-delta) + 1)=-beta*delta;

which implies that no steady state will exist when this parameter restriction is not satisfied.

Regarding your actual model: the steady state file should be similar to
Code: Select all
function [ys,check] = master_steadystate(ys,exo)
% function [ys,check] = master_steadystate(ys,exo)
% computes the steady state for the master.mod and uses a numerical
% solver to do so
% Inputs:
%   - ys        [vector] vector of initial values for the steady state of
%                   the endogenous variables
%   - exo       [vector] vector of values for the exogenous variables
%
% Output:
%   - ys        [vector] vector of steady state values fpr the the endogenous variables
%   - check     [scalar] set to 0 if steady state computation worked and to
%                    1 of not (allows to impos restriction on parameters)

global M_

% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
  paramname = deblank(M_.param_names(ii,:));
  eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
% initialize indicator
check = 0;


%% Enter model equations here
 
Dss = 0.12;
Rss = 1/betaa;

%
muss_T = (1 - betaa*(1-delta))/betaa;
muss_N = muss_T;
muss_C = muss_T;

%
TBss = (Rss - 1)*Dss;

%
Pss_C = 0.69;


% Commdity sector: {Kss_C/Lss_C and Wss_C}
KL_C = (alpha_C*Pss_C/muss_C)^(1/(1-alpha_C));
Wss_C = (1-alpha_C)*Pss_C*(KL_C^alpha_C);

% Tradable sector: {Capital to labor ratio = Kss_T/Lss_T and Wss_T}
KL_T = ((alpha_T/muss_T)*(((gammaa_T*muss_T)/(Pss_C*alpha_T))^gammaa_T))^(1/(1 - alpha_T - gammaa_T));
Wss_T = (1 - gammaa_T - alpha_T)*((gammaa_T*muss_T/Pss_C*alpha_T)^gammaa_T)*KL_T^(alpha_T + gammaa_T);


% Nontradable sector: {solve numerically for reer, Kss_N/Lss_N, Lss_N and Pss_N}
[FVAL,fval,exitflag] = fsolve(@F,[2;2;2;2],optimset('MaxIter', 10000));
if exitflag <1
    %indicate the SS computation was not sucessful; this would also be detected by Dynare
    %setting the indicator here shows how to use this functionality to
    %filter out parameter draws
    check=1; %set failure indicator
    return; %return without updating steady states
end


reer = FVAL(1);
KL_N = FVAL(2);
Lss_N = FVAL(3);
Pss_N = FVAL(4);


% Using labor supply conditions:
Lss_C = (Wss_C/reer)^(1/(omega_C - 1));
Lss_T = (Wss_T/reer)^(1/(omega_T - 1));
Wss_N = (Lss_N^(omega_N - 1))*reer;

% Capital stock in the steady state is found by
Kss_C = KL_C*Lss_C;
Kss_T = KL_T*Lss_T;
Kss_N = KL_N*Lss_N;

% Using the definition of commodity demand:
CMss_T = (gammaa_T/Pss_C)*(gammaa_T*muss_T/Pss_C*alpha_T)*(KL_T^(alpha_T + gammaa_T))*Lss_T;

% Production in the steady state:
Yss_T = (Kss_T^alpha_T)*(CMss_T^gammaa_T)*(Lss_T^(1 - gammaa_T - alpha_T));
Yss_C = (Kss_C^alpha_C)*(Lss_C^(1 - alpha_C));
Yss_N = (Kss_N^alpha_N)*(Lss_N^(1 - alpha_N));

% Trade balance:
TBss_C = Pss_C*(Yss_C - CMss_T);
TBss_T = TBss - TBss_C;

% Investment in the steady state
Iss_T = delta*Kss_T;
Iss_C = delta*Kss_C;
Iss_N = delta*Kss_N;

% Consumption of Tradable and nontradable goods:
Css_N = Yss_N;
Css_T = Css_N*((chi/(1 - chi))*Pss_N)^varphi;
Css = (chi*(Css_T^((varphi - 1)/varphi)) + (1-chi)*(Css_N^((varphi - 1)/varphi)))^(varphi/(varphi-1));

SIGMAss = Css_T + Pss_N*Css_N;
THETAss = Css - (Lss_T/omega_T)^omega_T - (Lss_N/omega_N)^omega_N - (Lss_C/omega_C)^omega_C;


%% end own model equations

for iter = 1:length(M_.params) %update parameters set in the file
  eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])
end
ys(:) = 0;
------------
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: steady state in log-linear system

Postby Cfarias » Mon Nov 21, 2016 11:05 am

Thank you very much Professor. Your help meant a lot.
Cfarias
 
Posts: 11
Joined: Sat Nov 12, 2016 6:21 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 10 guests