Commit 1b564157 authored by Johannes Pfeifer's avatar Johannes Pfeifer
Browse files

Clean up steady state file examples/NK_baseline_steadystate.m to make it Dynare 4 compatible.

Also shows how to use file to impose restrictions using the check indicator
parent 7ada720e
......@@ -15,7 +15,14 @@
* equations. Moreover, it makes use of a steady state file to i) set
* parameters that depend on other parameters that are potentially estimated
* and ii) solve a nonlinear equation using a numerical solver to find the steady
* state of labor.
* state of labor. It provides an example on how the steady state file can be used
* to circumvent some of the limitation of Dynare mod-file by accessing an external
* file that allows calling general Matlab routines. These capacities will mostly be
* interesting for power users. If one just wants to provide analytical steady state
* values and update parameters, the steady_state_model-block allows an easy and convenient
* alternative. It even allows calling numerical solvers like fsolve. For an example, see
* example3.mod
* The model is written in the beginning of period stock notation. To make the model
* conform with Dynare's end of period stock notation, we use the
* predetermined_variables-command.
function [ys,check] = NK_baseline_steadystate(ys,exe)
global M_ lgy_
if isfield(M_,'param_nbr') == 1
function [ys,check] = NK_baseline_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 i = 1:NumberOfParameters
paramname = deblank(M_.param_names(i,:));
eval([ paramname ' = M_.params(' int2str(i) ');']);
for ii = 1:NumberOfParameters
paramname = deblank(M_.param_names(ii,:));
eval([ paramname ' = M_.params(' int2str(ii) ');']);
% initialize indicator
check = 0;
%% Enter model equations here
......@@ -32,6 +45,11 @@ Lambdax=mu_z;
%set the parameter gammma1
if gammma1<0 % parameter violates restriction; Preventing this cannot be implemented via prior restriction as it is a composite of different parameters and the valid prior region has unknown form
check=1; %set failure indicator
return; %return without updating steady states
......@@ -49,9 +67,17 @@ vp=(1-thetap)/(1-thetap*PI^((1-chi)*epsilon))*PIstar^(-epsilon);
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
......@@ -68,27 +94,12 @@ g2=epsilon/(epsilon-1)*g1;
%% end own model equations
for iter = 1:length(M_.params)
for iter = 1:length(M_.params) %update parameters set in the file
eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])
if isfield(M_,'param_nbr') == 1
if isfield(M_,'orig_endo_nbr') == 1
NumberOfEndogenousVariables = M_.orig_endo_nbr;
NumberOfEndogenousVariables = M_.endo_nbr;
ys = zeros(NumberOfEndogenousVariables,1);
for i = 1:NumberOfEndogenousVariables
varname = deblank(M_.endo_names(i,:));
eval(['ys(' int2str(i) ') = ' varname ';']);
for i = 1:length(lgy_)
ys(i) = eval(lgy_(i,:));
check = 0;
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 ';']);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment