# Suggestions for those struggling to find steady states

**URL:** <https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478>\
**Category:** Dynare contributions and examples\
**Created:** [31 May 2010 09:51 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478 "2010-05-31T09:51:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cfp](https://forum.dynare.org/u/cfp)\
**Post date:** [31 May 2010 09:51 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/1 "2010-05-31T09:51:26Z")

</div>

Just posting a few things that worked for me. They may or may not help you.

[ul]  
_]Smooth any discontinuities in your model. I recommend the functional form max = ( sqrt( ( maximand1 - maximand2 )^2 + eps^2 ) + ( maximand1 + maximand2 ) ) / 2 for any maxes (where eps controls the maximum deviation from the true max). By differentiating this functional form once you can get a smooth step function, and differentiating it a second time gives a smooth delta function./_]  
_]Create a duplicate of your model file in which you remove any lags, leads or expectation operators, as well as any shocks. This ensures there are no auxiliary variables being solved for, thus minimising the dimensionality of the problem./_]  
_]Once you’ve done this, you will find that many equations are purely definitional, and can be replaced with dynare # definitions, further reducing dimensionality./_]  
_]Use a global solver, rather than the local ones Dynare includes. I particularly recommend CMA-ES [lri.fr/~hansen/cmaesintro.html](http://www.lri.fr/~hansen/cmaesintro.html) which is available for both C and Matlab, and seems remarkably powerful./_]  
_]If solver running times are too high, consider solving in C. You can take one of the CMA-ES example programmes and the automatically generated C residual code from Dynare, meaning this requires absolutely minimal coding. The speed-up for me was around 100x (no exaggeration)./_]  
_]Impose constraints in the objective function. I had a reasonably strong belief on the relative magnitudes of various variables in steady state, and encoded these beliefs into the objective function by adding a large number onto any steady state that violated them. This greatly helped avoiding local minima./_]  
_]Use homotopy. Having solved a special case using CMA-ES (after multiple runs with a bit of manual tweaking of starting values), I then modified my C code to slowly adjust the free parameter until it was the value I wanted./_]  
[/ul]

Hope this is of some use to someone.

T

---

<div class="post-metadata">

**Author:** ![olayenidynare](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@olayenidynare](https://forum.dynare.org/u/olayenidynare)\
**Post date:** [22 March 2011 16:31 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/2 "2011-03-22T16:31:09Z")

</div>

Maybe I happen to be one of the target audience. Please be more plain. If possible you may include a couple of examples. This may help a great many researchers in Dynare community. I tell you, the fear of steady state is the beginning of trouble for the modellers using dynare. I also think this approach could worked on to be included in later version of Dynare.

I appreciate this piece of info.

Thanks.

---

<div class="post-metadata">

**Author:** ![cfp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cfp](https://forum.dynare.org/u/cfp)\
**Post date:** [22 March 2011 16:35 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/3 "2011-03-22T16:35:14Z")

</div>

Which bit isn’t clear?

---

<div class="post-metadata">

**Author:** ![olayenidynare](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@olayenidynare](https://forum.dynare.org/u/olayenidynare)\
**Post date:** [22 March 2011 17:35 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/4 "2011-03-22T17:35:36Z")

</div>

Thanks for the prompt response.  
Forgive my bombsells, though I’m not new to Dynare. You particularly recommend using cmaes.m. I just downloaded this file.

The following are my questions.  
What does solving in C mean? I’m aware of the residual code generated by Dynare. Is this the same as C code you mean? Again are we solving outside Dynare? Where does homotopy come in? Lastly how do you achieve slowly adjust the free parameter?

Thanks

---

<div class="post-metadata">

**Author:** ![cfp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cfp](https://forum.dynare.org/u/cfp)\
**Post date:** [22 March 2011 17:43 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/5 "2011-03-22T17:43:27Z")

</div>

I would start by using the Matlab version of CMAES. Dynare will have generated a “…\_static.m” file which gives your objective function. You just need to pass it zeros for the x argument then your parameter vector.

C is a programming language. Dynare can generate a C version of your model which you can then use with the C version of CMAES. But I wouldn’t attempt this until you’ve tried everything else.

---

<div class="post-metadata">

**Author:** ![olayenidynare](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@olayenidynare](https://forum.dynare.org/u/olayenidynare)\
**Post date:** [22 March 2011 20:02 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/6 "2011-03-22T20:02:28Z")

</div>

I believe randomly generating the initial values for means and sigma required by CMAES isn’t the best. Purely for example pls.  
After inputing the code that looks like the one below and typing the calling m file  
paramv = [bla;bla;bla];  
iniy = randn(20,1);  
sigy = abs(randn(20,1));  
inix = [0;0;0];  
xmin = cmaes(‘nlrecap\_SS’,iniy,sigy,],inix,paramv);

I got an error message something about the dimensionality of vector. I think it has to do with cmaes.m:

??? In an assignment A(🙂 = B, the number of elements in A and B  
must be the same.

Error in ==\> cmaes at 620  
fitness.hist(1)=feval(fitfun, xmean, varargin{:});

Error in ==\> findysteadyvalues at 55  
xmin = cmaes(‘nlrecap\_SS’,iniy,sigy,],inix,paramv);

I reckon that the residual is an n element vector whereas fitness.hist(1) is being taken as a scalar. What can I do at this time? I’m really interested in getting to know this at once.

---

<div class="post-metadata">

**Author:** ![cfp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cfp](https://forum.dynare.org/u/cfp)\
**Post date:** [22 March 2011 22:28 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/7 "2011-03-22T22:28:32Z")

</div>

Look at the CMAES examples and check the function you’re calling has exactly the same structure. I expect it’s something like a row vector / column vector incompatibility. It’s a while since I used CMAES so I can’t be much more use really.

---

<div class="post-metadata">

**Author:** ![olayenidynare](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@olayenidynare](https://forum.dynare.org/u/olayenidynare)\
**Post date:** [21 April 2011 19:09 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/8 "2011-04-21T19:09:05Z")

</div>

Please does anybody know what the following mean:

??? Error using ==\> print\_info at 36  
MJDGGES returns the following error code: 62

Error in ==\> stoch\_simul at 71  
print\_info(info, options\_.noprint);

Error in ==\> phdfile2 at 1462  
info = stoch\_simul(var\_list\_);

Error in ==\> dynare at 132  
evalin(‘base’,fname) ;

Please help me

---

<div class="post-metadata">

**Author:** ![cfp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cfp](https://forum.dynare.org/u/cfp)\
**Post date:** [21 April 2011 19:18 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/9 "2011-04-21T19:18:06Z")

</div>

Put a breakpoint in stoch\_simul before the print\_info command. You have to remember to run dynare with the noclearall option else the breakpoint will be removed. This doesn’t look like it has anything to do with CMAES.

---

<div class="post-metadata">

**Author:** ![pguerron](https://forum.dynare.org/letter_avatar_proxy/v4/letter/p/aeb1de/32.png) [@pguerron](https://forum.dynare.org/u/pguerron)\
**Post date:** [1 June 2011 17:30 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/10 "2011-06-01T17:30:39Z")

</div>

The best suggestion is to compute the steady state by paper and pencil. This is doable for a very large class of models. Of course, it is time consuming but is a good checks on your model.

---

<div class="post-metadata">

**Author:** ![cfp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cfp](https://forum.dynare.org/u/cfp)\
**Post date:** [1 June 2011 17:34 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/11 "2011-06-01T17:34:39Z")

</div>

Yes of course that’s the first thing to attempt. (Or better still, get Maple to do it for you since that reduces the chance of errors.) But many models don’t have analytic steady states.

---

<div class="post-metadata">

**Author:** ![msh855](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@msh855](https://forum.dynare.org/u/msh855)\
**Post date:** [21 July 2013 14:08 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/12 "2013-07-21T14:08:06Z")

</div>

An example might really help indeed. I am among those that are struggling to find a Steady State and I have only basic numerical and programming skills. The consideration for “paper and pencil” is simply not working all the time, since there are non-linear equations that can not be handled.

I suggest, if someone really want to give a good example, is to use an OLG model with DEBT and non-zero deficits (ref: De La Croix and Michel, "Theory of Economic Growth: Dynamics and Policy in Overlapping Generations Model). Actually, this is what i am trying to do myself. I believe that this could be a good example for the following reasons. First, multiple steady states usually is the rule. Second, only under very restrictive conditions a steady state can be stable, third debt can be negative in such set up. The last one, I believe is really helpful since if someone does not know how to handle this, it might give negative values for capital and positive for debt, while is stochastic set up you might very easily say “bye bye” to a steady state 🙂

---

<div class="post-metadata">

**Author:** ![parantap](https://forum.dynare.org/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@parantap](https://forum.dynare.org/u/parantap)\
**Post date:** [2 October 2013 00:20 UTC](https://forum.dynare.org/t/suggestions-for-those-struggling-to-find-steady-states/1478/13 "2013-10-02T00:20:11Z")

</div>

Hi,

I am also in the same boat and I have been strggling to find the steady state. I know that the steady state exists and I have computed this seprately using fsolve nonlinear solver in matlab. I give the solution as guess values to dynare but does not work.

In the dynare manual section 4.10, it is suggested that if the solution is analytically known then put this in a steady-steady\_state\_model block. Create a seprate matlab file with dynare filename\_steadystate. It then creates a corresponding steady state file with the same name attaching a 2 at the end. The manual suggests to look at the example fs2000\_steadystate.m. I am not a matlab expert and I am basically trying to implement this in my problem by trying copy/paste but I am getting an error message that my function nesting is wrong. I think i am almost there. I am attaching the mod and the steady state files. Can anybdy help?

Parantap Basu[quant\_banking\_exo.mod](https://forum.dynare.org/uploads/default/original/2X/f/f0b4766c518aa5ee99b1c6e6cdc7eee09bf10154.mod) (2.01 KB)[quant\_banking\_exo\_steadystate.m](https://forum.dynare.org/uploads/default/original/2X/2/2c039c2f37035515bd4f622575be533cb673ab49.m) (852 Bytes)
