Page 1 of 1

converging to steady state

PostPosted: Thu Feb 04, 2016 10:36 am
by ogol77
Dear all,
I would be terribly thankful for help.
I have a model, which does not converge to steady state. I need to search through a parameter space for the parameter values at which the model converges, and I would be happy to find the way to have something like "if" loop: if the model convergest to steady state for any combination of the parameters - stop, otherwise, start from the beginning (with another parameter values).

I have the nested loops for the parameters, but I did not figure out how to tell dynare to check if there is a steady state and continue with the next parameter set if there is none.

Would be infinitely thankful for help!

Re: converging to steady state

PostPosted: Thu Feb 04, 2016 12:32 pm
by jpfeifer
You mean you need to find parameters where the steady state can be found?
First off, you need to find out whether the steady state for a particular parameter set exists as opposed to Dynare not being able to find it. If the latter is the problem, just changing the parameters is not advocated. Rather, you should try to analytically compute the steady state.
If the former is the problem and you want to know whether the steady state could be found, follow my code at http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4891
There, you loop over stoch_simul, which returns the variable info. This one stores the error codes. If info is 20, 21, or 22 the steady state was not found, was complex, or contained Inf/Nan, respectively.

Re: converging to steady state

PostPosted: Thu Feb 04, 2016 1:07 pm
by ogol77
Dear Johannes,

thank you very much for your kind and speedy reply!
Please, see below the code. What I am trying to do is to run through a parameter space and see if the model converges to the steady state (at any combination of the parameters). My problem is that I do not know how to force dynare to continue iteration and not to break the loop UNTIL it finds the combination of parameters which gives the steady state.

You are right, it makes sense to solve for the ss analytically first - but then I will still need to find the right parameters, very probably.

Would you be so kind to take a look at the code and may be you have some idea how to force the loop not to break until... The thing is I do not know how to state the condition for break - e.g. what is the value (in output?) that means that steady state has been found?

Can not thank you enough!

The code:

//1. Variable declaration
//------------------------------------------------------------------------------------------------------------------------

var pr, ri, rl, rd, d, dstar, pai, paistar, n, nstar, ne, nestar, dt, nt, net, a, m, lnpr, lnri, lnrl, lnrd, lnd, lnnn, lnne, lndstar, lnnstar, lnnestar, lndt, lnnt, lnnet;

//8 variables + 2 shocks

varexo ua um;

//------------------------------------------------------------------------------------------------------------------------
// 2. Parameter declaration and calibration
//------------------------------------------------------------------------------------------------------------------------

parameters beta, alpha, phi, gama, csi, pho, kai, mu, roa, rhom;


pho_vec=0.1:0.05:0.25;
mu_vec=0.05:0.05:0.15;
beta_vec=0.85:0.005:0.9;



for p=1:length(pho_vec)
for q=1:length(mu_vec)
for i=1:length(beta_vec)


alpha=0.7;
phi=2;
gama=3;
csi=0.2;
gama=3;
csi=0.2;
roa=0.95;
rhom = 0.9;
kai=2.1;

pho=pho_vec(p);
mu=mu_vec(q);
beta=beta_vec(i);


//-----------------------------------------------------------------------------------------------------------------------
// 3. The model
//-----------------------------------------------------------------------------------------------------------------------


model;


a = roa*a(-1)+ua;
m = rhom*m(-1)+um;
pr = exp(a) - alpha*exp(a)*ri;
rl = exp(a)/alpha - phi*dt;
rd = gama*dt;

ri = 1/alpha- ((phi/2*exp(a))*dt);
dt * (exp(a)/alpha - (phi+gama)*dt - csi) = - (exp(a)/alpha - 2*(phi+gama)*dt - csi)*d; //individual deposits from banks' F.O.C.

dt * (exp(a)/alpha - (phi+gama)*dt - csi - mu*exp(m)) = - (exp(a)/alpha - 2*(phi+gama)*dt - csi - mu*exp(m))*dstar; //individual deposits from banks' F.O.C.

pai = pr*((1+rl)-(1+rd)-csi)*d;
paistar = pr*((1+rl)-(1+rd)-csi-mu*exp(m))*dstar;
pai = kai*(1-beta*(1-pho));
paistar = kai*(1-beta*(1-pho));
n(+1) = (1-pho)*(n+ne);
nstar(+1) = (1-pho)*(nstar+nestar);
dt = ((n/(1-pho))*d+(nstar/(1-pho))*dstar);
nt = n + nstar;
net = ne + nestar;
lnpr = ln(pr);
lnri = ln(ri);
lnrl = ln(rl);
lnrd = ln(rd);
lnd = ln(d);
lnnn = ln(n);
lnne = ln(ne);
lndstar = ln(dstar);
lnnstar = ln(nstar);
lnnestar = ln(nestar);
lndt = ln(dt);
lnnt = ln(nt);
lnnet = ln(net);


end;

//--------------------------------------------------------------------------------------------------------------------------
// 4. Steady state
//--------------------------------------------------------------------------------------------------------------------------

initval;

pr = 0.0530488;
ri = 1.72173;
rl = 1.62528;
rd = 0.289357;
d = 5.75273;
dstar = 5.93008;
pai = 0.255102;
paistar = 0.255102;
n = 0.0171855;
nstar = 0.0166716;
ne = 0.000440655;
nestar = 0.000427476;
dt = 2.5;
nt = 0.02;
net = 0.0008;
a = 0;
lnpr = ln(pr);
lnri = ln(ri);
lnrl = ln(rl);
lnrd = ln(rd);
lnd = ln(d);
lnnn = ln(n);
lnne = ln(ne);
lndstar = ln(dstar);
lnnstar = ln(nstar);
lnnestar = ln(nestar);
lndt = ln(dt);
lnnt = ln(nt);
lnnet = ln(net);

end;

resid(1);

steady;

//---------------------------------------------------------------------------------------------------------------------------
// 5. shocks
//---------------------------------------------------------------------------------------------------------------------------

shocks;
var ua; stderr 0.01;
//var um; stderr 0.01;
end;


stoch_simul (irf=30,order=1);

end
end
end

Re: converging to steady state

PostPosted: Thu Feb 04, 2016 2:50 pm
by jpfeifer
Please take a look at the link I provided above. You cannot easily loop within a mod-file. You need to write a loop in Matlab. All information is there.

Re: converging to steady state

PostPosted: Thu Feb 04, 2016 3:18 pm
by ogol77
Thank you, i will! However, could you give me a hint what to use as a criteria for steady state convergance to break the loop once the ss is achieved?? Thanks once again - i am very gratefull for your help and valuable time!

Re: converging to steady state

PostPosted: Sat Feb 20, 2016 7:29 am
by jpfeifer
You should break the loop once info is 0. This corresponds to a steady state tolerance of about 1e-6.