Hi Stéphane,
thanks a lot!
D
Hi Stéphane,
thanks a lot!
D
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
Thanks a lot! It is very useful and I will try to use it soon!
Dario
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
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,:) ';' ])
by
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
Thanks Johannes,
Sorry for the late reply (paternity leave).
I’m resubmiting the file with your correction.
Gilles
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.
Best,
Stéphane.[/quote]
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.
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 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
[/code]
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
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 =
evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag);
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_,
bayestopt_);
Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);
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:
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.
If I use your template I get an error. The first variable from M_.endo_names(i, 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?
In order to get the external steady file to work I replaced:
%varname = deblank(M_.endo_names(i,:));
%eval('ys(' int2str(i) ') = ' varname ';']);
with
because my model is log-linearised and in steady state all log-deviations should be 0.
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!
Daniel.
I am a new user of Dynare. I tried to enter my model’s steady state ratios to jpfeifer’s code but is gives me the error of unknown variables. Is there any specific method for writing steady state equations ??? I guess I should write them in this way:
[quote=“gbel”]Thanks Johannes,
Sorry for the late reply (paternity leave).
I’m resubmiting the file with your correction.
Gilles[/quote]
Hi,
thanks for the steady state file. Can I use it to calculate my model’s steady state? Should I change some codes in the files? There are 102 equations and 102 variables in my model.
I have been working with the model for one month, but I cannot get the right steady state by hand. I appreciate that you share your code here. Thank again and I hope for a further help from you. thanks!!!
cindy