External Matlab Steady State solver

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.

External Matlab Steady State solver

Postby erikignasi » Sun Oct 02, 2016 5:30 pm

Hello everyone!

I'm a 4th year undergraduate student from Barcelona. I'm currenlty writing my thesis on simulating calibrated basic neoclassical and new keynesian models on Spain and UK by using Dynare. For now, I've adopted Jesus Fernandez-Villaverde's RBC model (http://economics.sas.upenn.edu/~jesusfv/teaching.html) and computed the Steady State per hand. I want to write a Steady State solver Matlab file (.m) so to link it to my Dynare Script.

However, I'm very new to Dynare as well as to Matlab (I'm using both for the first time since I started with my Thesis this semester). Hence, I had some problems on writing a Matlab function for my Steady State. Even though I tried to understand some of the steady state .m files in the Dynare examples folder (i.e.NK_baseline) and tried to adapt it for my particular case, I don't understand many of the commands that are displayed.

Therefore, I would really appreciate any kind of help as for instance giving me some advise on how to write successfully a Steady State function on Matlab, or having a look at my attached .mod files for my Neoclassical model and explain to me how may I create a .m file for my Steady State equations.

What is more, looking for some other postings I found a Steady State .m file for an RBC model for the Log_linearized case provided by the user "Sesser" (viewtopic.php?f=1&t=8373&p=24693&hilit=steady+state+external#p24693). Given I did not understand much of the content neither I would also appreciate some help on this (maybe it is more appropiate to adapt my Steady State solver of my model on this .m file)

Thanks in advance for any useful help.
Attachments
rbc_steadystate.m
RBC steady state .m file for a log_linearized model from another posting reply of "Sesser" (http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=8373&p=24693&hilit=steady+state+external#p24693). I would take this Steady State .m file and adapt it to my case if I would know how. Any help particularly on this file would be great.
(1.66 KiB) Downloaded 134 times
SS_solver_Neoclassical_Model.mod
Steady State equations derived per hand and written in a .mod file. I'm aware of the possibility of inserting this as a Steady State block directly in my Dynare script. However, I want to do it through a Matlab function.
(290 Bytes) Downloaded 117 times
Neoclassical_Model_UK.mod
Adapted Jesus Fernandez Villaverde's RBC model with UK data parameter calibration (Steady State in this case was computed by non-linear Newton type processor default solver)
(881 Bytes) Downloaded 101 times
erikignasi
 
Posts: 10
Joined: Sun Oct 02, 2016 4:49 pm
Location: Barcelona

Re: External Matlab Steady State solver

Postby jpfeifer » Tue Oct 04, 2016 8:54 am

The steady state file should be:
Code: Select all
function [ys,check] = Neoclassical_Model_UK_steadystate(ys,exo)
% function [ys,check] = NK_baseline_steadystate(ys,exo)
% computes the steady state for the NK_baseline.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

l = (1 - alppha)*(1/betta - (1 - delta))/(psii*(1/betta - (1 - delta) - alppha*delta) + (1 - alppha)*(1/betta - (1 - delta)));
k = ((alppha/(1/betta - (1 - delta)))^(1/(1 - alppha)))*l;
c = ((1/betta - (1 - delta) - alppha*delta)/alppha)*k;
invest = delta*k;
y = c+invest;
y_l = y/l;
z = 0;
e = 0;

%% 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

NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically
for ii = 1:NumberOfEndogenousVariables
  varname = deblank(M_.endo_names(ii,:));
  eval(['ys(' int2str(ii) ') = ' varname ';']);
end

You need to use the header and footer provided in NK_baseline_steadystate.m and then add equations defining the steady state for every single variable in your model. Because Matlab has trouble with parameters that have the same name as internal functions, I needed to rename the parameter names and i. The mod-file would be
Code: Select all
// 1) Definition of variables
 
var y c k invest l y_l z;
varexo e;
parameters alppha betta delta psii rho sigma;
 
// 2) Calibration
 
alppha = 0.371;
betta = 0.973;
delta = 0.026;
psii = 3.11;
rho = 0.951;
sigma = 0.0043;
 
// 3) Model
 
model;
(1/c) = betta*(1/c(+1))*(1+alppha*(k^(alppha-1))*(exp(z(+1))*l(+1))^(1-alppha)-delta);
psii*c/(1-l) = (1-alppha)*(k(-1)^alppha)*(exp(z)^(1-alppha))*(l^(-alppha));
c+invest = y;
y = (k(-1)^alppha)*(exp(z)*l)^(1-alppha);
invest = k-(1-delta)*k(-1);
y_l = y/l;
z = rho*z(-1)+e;
end;
 
// 4) Computation

shocks;
var e = sigma^2;
end;

steady;
check;

stoch_simul;

Note that the naming of the steadystate-file must be consistent with the name of the mod-file, i.e. mod_file_name_steadystate.m
------------
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: External Matlab Steady State solver

Postby erikignasi » Tue Oct 04, 2016 6:25 pm

Dear Dr. Pfeifer,

Thanks a lot for your help! I really appreciated your advise and everything worked perfectly well!
Auf diesem Wege möchte ich mich nochmal ganz herzlich bei Ihnen "auf Deutsch" für Ihre Unterstützung bedanken.

Best wishes,

Erik
erikignasi
 
Posts: 10
Joined: Sun Oct 02, 2016 4:49 pm
Location: Barcelona


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests