Steady state file


I am trying to write a file which contains the steady state of my model. I call the file example_steadystate.m (the mod file is called example of course). Either I write the file as a regular script or as a function, I always get an error message when I try to use it.

How should the steady state file be written(as a function? If so, what inputs and outputs)? How should I call it from the .mod file? I think it would be helpful to have a small example posted on the webpage.

Thanks a lot!


1 Like

Hi Dario,

Here is an example with deterministic simulation of a growthless optimal growth model (it is exactly the same approach for stochastic models).

Note that if the steady state is only known partially the user can use a Newton like routine inside the *_steadystate.m file.

Note also that this example will run only with Dynare version 4.

dog_steadystate.m (1.87 KB)
dog.mod (2.09 KB)

1 Like

Hi Stéphane,

thanks a lot!


This is a small improvement on Stéphane’s steadystate file. It’s a function that searches for the existence of model_steadystate.mod or model_steadystate.dyn (if your model is called “model”) than creates the model_steadystate.m file with Stéphane’s specifications. If you don’t have this .mod or .dyn file, you can still use the .m file.

It’s simpler because you just put the steady state equations in the .mod file and it does the rest. I’ve modified Stéphane’s stuff to work with both Dynare 3 and 4.

To install, put steadystate.m in your path and add the line: steadystate(fname); in the file dynare.m somewhere in the begining.


Thanks a lot! It is very useful and I will try to use it soon!


New variable creations in 4.1 made the steadystate.m file stop working.

This one will work with 4.1, as well as 4.0 and 3.0


Darn! forgot the file

Thanks for the file that automatically adds the required code to feed the steady state values from the Matlab .m-file back to Dynare. However, I am experiencing some problems when updating calibrated parameters that are also computed in the steady state file. The code created by steadystate.m does not change the original parameter values. I could trace back the problem to the following line:

evalin('base', 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])

The call of M_ in the “base” workspace of Matlab seems to be not working (Matlab 2009b, WinXP 64bit). However, as the structure M_ is set as a global variable by the steadystate.m, simply replacing

evalin('base', 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])


eval( 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])

does the job (probably a conflict between the variable in the “base” workspace of Matlab and the variable being global).


Thanks Johannes,

Sorry for the late reply (paternity leave).

I’m resubmiting the file with your correction.

steadystate.m (2.42 KB)

[quote=“StephaneAdjemian”]Hi Dario,

Here is an example with deterministic simulation of a growthless optimal growth model (it is exactly the same approach for stochastic models).

Note that if the steady state is only known partially the user can use a Newton like routine inside the *_steadystate.m file.

Note also that this example will run only with Dynare version 4.



can I use the *_steadystate.m file posted as a model for my *_steadystate.m? Should I just change the equations linked to the model?


You need the following code to read from and write the parameters and steady state values back to Dynare. The file posted previously is most probably obsolete. Note that you have to change the * in the name of the function to the name of your mod-file and to save it with that name.

[code]function [ys,check] = *steadystate(ys,exe)
global M

if isfield(M_,‘param_nbr’) == 1
NumberOfParameters = M_.param_nbr;
for i = 1:NumberOfParameters
paramname = deblank(M_.param_names(i,:));
eval( paramname ’ = M_.params(’ int2str(i) ‘);’]);
check = 0;

%%%% Model equations to be entered here

for iter = 1:length(M_.params)
eval( ‘M_.params(’ num2str(iter) ') = ’ M_.param_names(iter,:slight_smile: ‘;’ ])

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;

The file posted is not obsolete. It’s been updated for the lastest version thanks to your own recommandation. The advantage over the code you posted is that the steadystate.m file will also update deep parameters during estimation.

Did you check? I use it at work and it works.


Sorry Gilles for the misunderstanding,

with obsolete, I was not referring to your steadystate.m. I was referring to the first code dog_steadystate.m posted by Stephanes, because ornellas.r wanted to just change the model equations in between.

I know that your code works and really appreciate it. Actually, the code I posted is was generated using your file. However, sometimes people have trouble using it. Particularly the structure of putting the equations in a mod-file called *_steadystate.mod and then handing over a string with the name of the original *.mod file to invoke the code manually can be tricky for beginners. Changing dynare.m to automatize is not easy either. Hence, I just posted the basic lines that are produced by your code. This of course also means that the deep parameters are updated as in your code.

Your right, changing dynare.m is too much for a new user. Maybe I should see if Stéphane or Michel want to add steadystate.m to Dynare. There are no legal issues as long as my employer’s name stays in the file.

Thank you all for the answers…

Dear All

I am using the steady state file given above in the post by jpfeifer » Mon Nov 08, 2010 9:32 pm
It worked fine up until I tried dynare 4.3.0

Immediately after loading observations it crashes and writes

Loading 43 observations from UKdata.m

Attempt to reference field of non-structure array.

Error in evaluate_steady_state_file (line 95)
if max(abs(residuals)) > options.dynatol.f

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

Error in dynare_estimation_init (line 341)
oo_.steady_state =

Error in dynare_estimation_1 (line 59)
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] =
dynare_estimation_init(var_list_, dname, ], M_, options_, oo_, estim_params_,

Error in dynare_estimation (line 70)

I have checked: immediately after it plots the priors it gets to the line

if max(abs(residuals)) > options.dynatol.f

and at this point options.dynatol.f does not seem to be defined. Before it was 1e-5. So it forgets this value somehow.

Can I fix it somehow?

Could you please post the mod- and the steady state file that generate this error.

Sorry, i got distracted.

I traced this - there is some kind of bug, the error appears because some kind of options (including options.dynatol.f) are redefined in the middle. However, because of my model is linear and the steady state is zero, I just killed these nuisance lines, and it all worked. All I wanted this time is to check that different versions give me the same result. They did. So I cannot be bothered to dig deeper this time.

Dear all,

regarding the external steady steate file I would have the following questions please:

  1. if the model is log-linearised then the loop at the end of the example steady state file can also include ys(i)=0; We would have only the equations for the parameters in the file.

  2. If I use your template I get an error. The first variable from M_.endo_names(i,:slight_smile: is “v_K” in my case, but I get an error message that the variable is unknown. “v_K” is declared as a variable in the *.mod file. Why do I get this error message? Do I need to include it somehow as an input parameter in the *_steadystate function?

  3. In order to get the external steady file to work I replaced:

%varname = deblank(M_.endo_names(i,:)); %eval('ys(' int2str(i) ') = ' varname ';']);


because my model is log-linearised and in steady state all log-deviations should be 0.

  1. When I try to estimate my model I get the Blanchard-Kahn error and that a steady state could not be calculated. However, I get no error when I run stoch_simul(). Everything seems to work fine then.

I try then to use the option lik_init=2 instead of lik_init=1(even if my model is stationarised), but in this case the csminwel algorithm iterates 1000 times and at the end I get the error that the Hessian is negative(posterior maximisation error). My data is detrended with HP filter and I take log differences. The measurement equations are accordingly.( OBS_x = x - x(-1));

Any suggestions are higly appreciated!
Thank you in advance!

  1. Yes, you can do that.
  2. You get the error, because in the steady state file you try to assign the value assigned to v_K in the steady state file to the v_K defined in the mod-file. However, you did not assign a value to v_K in the steadystate file.
  3. By doing this, you now assign a value to v_K (equivalent to defining v_K=0 in the file before). Thus, it works now.
  4. It sounds as if you use wrong initial parameter values for estimation.