steady state file

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 file

Postby dareios82 » Tue Aug 12, 2008 4:14 pm

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
dareios82
 
Posts: 10
Joined: Sat Jun 30, 2007 3:01 pm

Re: steady state file

Postby StephaneAdjemian » Wed Sep 03, 2008 9:00 am

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.
Attachments
dog_steadystate.m
matlab file with the definition of the steady state.
(1.87 KiB) Downloaded 3858 times
dog.mod
(2.09 KiB) Downloaded 3190 times
Stéphane Adjemian
Université du Maine, GAINS and DynareTeam
https://stepan.adjemian.eu
StephaneAdjemian
 
Posts: 429
Joined: Wed Jan 05, 2005 4:24 pm
Location: Paris, France.

Postby dareios82 » Wed Sep 03, 2008 10:56 am

Hi Stéphane,

thanks a lot!

D
dareios82
 
Posts: 10
Joined: Sat Jun 30, 2007 3:01 pm

Re: steady state file

Postby gbel » Thu Dec 04, 2008 9:11 pm

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
Last edited by gbel on Fri Mar 05, 2010 4:32 pm, edited 2 times in total.
gbel
 
Posts: 33
Joined: Thu Sep 04, 2008 8:34 pm
Location: Québec

Re: steady state file

Postby dareios82 » Mon Dec 08, 2008 10:10 pm

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

Dario
dareios82
 
Posts: 10
Joined: Sat Jun 30, 2007 3:01 pm

Re: steady state file

Postby gbel » Fri Jan 29, 2010 7:55 pm

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
gbel
 
Posts: 33
Joined: Thu Sep 04, 2008 8:34 pm
Location: Québec

Re: steady state file

Postby gbel » Fri Jan 29, 2010 7:56 pm

Darn! forgot the file
Last edited by gbel on Fri Mar 05, 2010 4:33 pm, edited 3 times in total.
gbel
 
Posts: 33
Joined: Thu Sep 04, 2008 8:34 pm
Location: Québec

Re: steady state file

Postby jpfeifer » Sun Feb 21, 2010 4:18 pm

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

Postby gbel » Tue Mar 02, 2010 4:43 pm

Thanks Johannes,

Sorry for the late reply (paternity leave).

I'm resubmiting the file with your correction.

Gilles
Attachments
steadystate.m
(2.42 KiB) Downloaded 1585 times
gbel
 
Posts: 33
Joined: Thu Sep 04, 2008 8:34 pm
Location: Québec

Re: steady state file

Postby ornellas.r » Mon Nov 08, 2010 12:00 pm

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.
ornellas.r
 
Posts: 3
Joined: Thu Oct 07, 2010 6:57 pm

Re: steady state file

Postby jpfeifer » Mon Nov 08, 2010 9:32 pm

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

Postby gbel » Fri Nov 12, 2010 2:02 am

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
gbel
 
Posts: 33
Joined: Thu Sep 04, 2008 8:34 pm
Location: Québec

Re: steady state file

Postby jpfeifer » Fri Nov 12, 2010 7:22 am

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.
------------
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 file

Postby gbel » Fri Nov 12, 2010 1:57 pm

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.
gbel
 
Posts: 33
Joined: Thu Sep 04, 2008 8:34 pm
Location: Québec

Re: steady state file

Postby ornellas.r » Tue Nov 16, 2010 1:42 pm

Thank you all for the answers...
ornellas.r
 
Posts: 3
Joined: Thu Oct 07, 2010 6:57 pm

Next

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 10 guests