Page **1** of **3**

### steady state file

Posted:

**Tue Aug 12, 2008 4:14 pm**
by **dareios82**

Hi,

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!

Dario

### Re: steady state file

Posted:

**Wed Sep 03, 2008 9:00 am**
by **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.

Best,

Stéphane.

Posted:

**Wed Sep 03, 2008 10:56 am**
by **dareios82**

Hi Stéphane,

thanks a lot!

D

### Re: steady state file

Posted:

**Thu Dec 04, 2008 9:11 pm**
by **gbel**

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.

Gilles

### Re: steady state file

Posted:

**Mon Dec 08, 2008 10:10 pm**
by **dareios82**

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

Dario

### Re: steady state file

Posted:

**Fri Jan 29, 2010 7:55 pm**
by **gbel**

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

Gilles

### Re: steady state file

Posted:

**Fri Jan 29, 2010 7:56 pm**
by **gbel**

Darn! forgot the file

### Re: steady state file

Posted:

**Sun Feb 21, 2010 4:18 pm**
by **jpfeifer**

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:

- Code: Select all
`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

- Code: Select all
`evalin('base',[ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])`

by

- Code: Select all
`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).

Johannes

### Re: steady state file

Posted:

**Tue Mar 02, 2010 4:43 pm**
by **gbel**

Thanks Johannes,

Sorry for the late reply (paternity leave).

I'm resubmiting the file with your correction.

Gilles

### Re: steady state file

Posted:

**Mon Nov 08, 2010 12:00 pm**
by **ornellas.r**

StephaneAdjemian wrote: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.

Best,

Stéphane.

Hi,

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?

Thanks.

### Re: steady state file

Posted:

**Mon Nov 08, 2010 9:32 pm**
by **jpfeifer**

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: Select all
`function [ys,check] = *_steadystate(ys,exe)`

global M_ lgy_

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) ');']);

end

check = 0;

end

%%%% Model equations to be entered here

for iter = 1:length(M_.params)

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

end

if isfield(M_,'param_nbr') == 1

if isfield(M_,'orig_endo_nbr') == 1

NumberOfEndogenousVariables = M_.orig_endo_nbr;

else

NumberOfEndogenousVariables = M_.endo_nbr;

end

ys = zeros(NumberOfEndogenousVariables,1);

for i = 1:NumberOfEndogenousVariables

varname = deblank(M_.endo_names(i,:));

eval(['ys(' int2str(i) ') = ' varname ';']);

end

else

ys=zeros(length(lgy_),1);

for i = 1:length(lgy_)

ys(i) = eval(lgy_(i,:));

end

check = 0;

end

end

### Re: steady state file

Posted:

**Fri Nov 12, 2010 2:02 am**
by **gbel**

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.

Gilles

### Re: steady state file

Posted:

**Fri Nov 12, 2010 7:22 am**
by **jpfeifer**

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.

### Re: steady state file

Posted:

**Fri Nov 12, 2010 1:57 pm**
by **gbel**

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.

### Re: steady state file

Posted:

**Tue Nov 16, 2010 1:42 pm**
by **ornellas.r**

Thank you all for the answers...