Suggestions for those struggling to find steady states

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

]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 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./]

Hope this is of some use to someone.


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.


Which bit isn’t clear?

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?


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.

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(:slight_smile: = 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.

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.

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

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.

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.

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.

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 :slight_smile:


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 Basuquant_banking_exo.mod (2.01 KB)quant_banking_exo_steadystate.m (852 Bytes)