# Ramsey Policy

Hi,

I’m trying to work out how to run the Ramsey_Policy in dynare. The problem that I am having is that I do not quite understand what it means to specify the steady state of the model CONDITIONAL on the instruments used. I tried to follow the Michel Juillard’s set of notes and implement his example (see attached file).

The code for a generic model provided in the notes is as follows:

[code]var pai, c, n, r, a;
varexo u;
parameters beta, rho, epsilon, omega, phi, gamma;

beta=0.99;
gamma=3;
omega=17;
epsilon=8;
phi=1;
rho=0.95;
model;
a = rhoa(-1)+u;
1/c = beta
r/(c(+1)pai(+1));
pai
(pai-1)/c = betapai(+1)(pai(+1)-1)/c(+1)+epsilonphin^(gamma+1)/omega-exp(a)n(epsilon-1)/(omega*c);
exp(a)n = c+(omega/2)(pai-1)^2;
end;
initval;
r=1;
end;

a = 0;
pai = betar;
c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega);
n = c+(omega/2)
(pai-1)^2;
end;
shocks;
var u; stderr 0.008;
end;

ramsey_policy(planner_discount=0.99,order=1,instruments=®);

function c = find_c(c0,pai,beta,epsilon,phi,gamma,omega)
c = csolve(@nk_ss,c0,],1e-8,100,pai,beta,epsilon,phi,gamma,omega);
function r = nk_ss(c,pai,beta,epsilon,phi,gamma,omega)
r = pai*(pai-1)/c - betapai(pai-1)/c-epsilonphi(c+(omega/2)(pai-1)^2)^(gamma+1)/omega+(c+(omega/2)(pai-1)^2)(epsilon-1)/(omegac);[/code]

The problem is that dynare does not recognise the command @nk_ss and the code cannot be implemented (see error message below) even if I name the .mod file as nk_ss:

Starting Dynare (version 4.4.3).
Starting preprocessing of the model file …
ERROR: nk_ss.mod: line 35, col 12: character unrecognized by lexer

Error using dynare (line 174)
DYNARE: preprocessing failed

I have read the dynare manual and I understand that you need to omit he Taylor rule in the model (if it applies), that commands “steady” are incompatible with ramsey_policy, I know how the policy objective is specified and what the ramsey_policy options are. The only thing I do not understand is how the steady state has to be specified (hence the example above cannot be implemented, and I am using unstable version of dynare 4.4.3). I tried looking into other topics on similar issues, but running my model with just initval doesn’t work. Then specifying the instrument in the initval, whereas the rest of the model in steady_state_model block leads to singularity (as in other topics here). So I could really use some help in trying to find these conditional steady states, because I am sure that this is the root of all problems. There isn’t a lot of material out there. Andy Levin’s codes are also outdated and don’t work on recent versions of Dynare.

Thank you.
nk_ss.mod (993 Bytes)
Ramsey Policy.pdf (175 KB)

3 Likes

You can find an example here: github.com/DynareTeam/dynare/blob/master/tests/optimal_policy/Ramsey/ramsey_ex.mod. The find_c.m file you also need in the same folder is at github.com/DynareTeam/dynare/blob/master/tests/optimal_policy/Ramsey/find_c.m
r is declared as an instrument. Given any value of the instrument entered to the steady_state_model-block, an analytical steady state is provided. If you want, you can implement something similar within a proper steady state file. An example here is the NK_baseline.mod in the Dynare examples folder. Note that you should use the current unstable version (soon to be 4.5) for Ramsey with instruments as several bugs related to this have been fixed.

1 Like

Following your guidance, I can now run the example without any problems. However, I still don’t think I quite understand what the software is doing, because I can’t apply it to any other models (I always get an error message that says either “too many input arguments” or “not enough input arguments”).

The way I understand it is as follows. The line in the steady_state_model block of the mod file

Returns a non-zero value for c, which is found numerically from the find_c.m file. This is done because the steady state value of the instrument r is ex ante not known and thus the analytical solution to the steady state of c is not possible. Then the find_c.m file has the following:

function c = find_c(c0,pai,beta,epsilon,phi,gamma,omega)
c = csolve(@nk_ss,c0,],1e-8,100,pai,beta,epsilon,phi,gamma,omega);
end

function r = nk_ss(c,pai,beta,epsilon,phi,gamma,omega)
r = pai*(pai-1)/c - beta*pai*(pai-1)/c-epsilon*phi*(c+(omega/2)*(pai-1)^2)^(gamma+1)/omega +(c+(omega/2)*(pai-1)^2)*(epsilon-1)/(omega*c);
end

Where c0 is the initial value (=0.96 in the mod file). The next part is less clear. The arguments inside find_c, are they ALL the model parameters (except for technological progress persistence) or are they only the parameters that would affect c from equation 3?

Why is one of the endogenous variables (i.e. pai) in the find_c function? Is it because the steady state value of pai directly depends on the value of the instrument and it is recursively used in the steady state of c?

Then in the second line where csolve is used

c=csolve(@nk_ss,c0,],1e-8,100....

@nk_ss applies some sort of numerical optimisation algorithm (does @ indicate a model local variable?), where c0 is the initial value, ] specifies the gradient, 1e-8 is the terminal condition (i.e. ad hoc value for when the gradient is sufficiently small) and 100 is the maximum number of iterations to be used. So, the values of (ALL?) the model parameters are specified at this step because they influence the value of the steady state of c?

Then the last part is specifying the instrument:

r = nk_ss(c,pai,beta,epsilon,phi,gamma,omega)

Again, I’m not sure what nk_ss stands for so I can only guess that its a numerical optimisation algorithm (some sort of “FUN” from dynare internals). Why does the value of c or anything else enter the specification of nk_ss (its important to know if it is to be applied in other contexts)? And is this the policy makers constraint (which is the recursive solution of equation 3 equated to the value of the instrument)?:

r = pai*(pai-1)/c - beta*pai*(pai-1)/c-epsilon*phi*(c+(omega/2)*(pai-1)^2)^(gamma+1)/omega +(c+(omega/2)*(pai-1)^2)*(epsilon-1)/(omega*c);

As always, thank you very much for the help and support.

A steady state file is always recursive as you solve for one variable after another. We have

a = 0; pai = beta*r; c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega); n = c+(omega/2)*(pai-1)^2;
That is, we first find the steady state for a, then for pai, then for c, and last for n. That is the reason we can use pai when solving for c. As you can see, the value for pai is therefore handed over to the find_c.m function.
The problem with the model is that even if you know the value of the instrument, the particular nonlinear structure of the model makes it impossible to solve for c. You need to use a root finder for this. The function find_c does exactly this. Given the value of pai and the values of the parameter appearing in the consumption equation after substituting out labor (therefore there is no need to pass all parameters), we search for the root of this equation.
Looking at the find_c.m file, you can see that it contains a nested function nk_ss in line 5 following. This function could have been a separate m-file, but here it is nested. This function computes the residual of the consumption FOC after labor has been substituted out. That is, with the correct value for consumption, the residual will be 0. That is what is done with csolve: starting with c0 find the value that returns a zero residual. The @ is used by Matlab to create a function handle, i.e. tell the solver that nk_ss is the function we need to solve.

3 Likes

I think I understand the find_ and nk_ss commands better now. I applied similar logic to my model, but I think I ran into a similar problem as in this topic: [Problems with Ramsey policy).

Please see the code attached to this message. I specify the nominal interest rate ® as an instrument, which appears in the stochastic discount factor (LAMBDA). The CPI inflation (PI_CPI) is thus a function of LAMBDA and beta (the time invariant discount factor), which must be obtained using find_ command:

function PI_CPI = find_PI_CPI(PI_CPI0, LAMBDA, beta) PI_CPI = csolve(@nk_ss,PI_CPI0,],1e-8,100, LAMBDA, beta); end

Then I specify the function for the residuals of the instrument (i.e. the Euler equation):

function r = nk_ss(PI_CPI, LAMBDA, beta) r = (PI_CPI*LAMBDA)/beta; end

The steady_state_model block is solved recursively and it is conditional on the instrument value. However, when I run the code I obtain quite a number of rank deficiency warnings such as:

[code]Warning: Rank deficient, rank = 0, tol = NaN.

In dyn_ramsey_static_dyn_ramsey_static_1 (line 152)
In dyn_ramsey_static>@(x)dyn_ramsey_static_1(x,M,options_,oo) (line 40)
In csolve (line 112)
In dyn_ramsey_static (line 55)
In resol (line 104)
In stoch_simul (line 88)
In ramsey_policy (line 25)
In FINOP_RAMSEY (line 650)
In dynare (line 180) [/code]

Until Matlab stops and gives another error at the end:

Attempted to access ys_(50); index out of bounds because numel(ys_)=40. Error in FINOP_RAMSEY_steadystate2 (line 44) ys_(80)=ys_(50)*(-(ys_(18)*1/(ys_(26)*ys_(15)))); Error in evaluate_steady_state_file (line 54) [ys,params1,check] = h_steadystate(ys_init, exo_ss, params); Error in dyn_ramsey_static (line 61) [xx,params,check] = evaluate_steady_state_file(ys,exo_ss,M,options_); Error in evaluate_steady_state (line 55) [ys,params] = dyn_ramsey_static(ys_init,M,options,oo); Error in resol (line 104) [dr.ys,M.params,info] = evaluate_steady_state(oo.steady_state,M,options,oo,0); Error in stoch_simul (line 88) [oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); Error in ramsey_policy (line 25) info = stoch_simul(var_list); Error in FINOP_RAMSEY (line 650) ramsey_policy(var_list_); Error in dynare (line 180) evalin('base',fname) 

Hence, there are only 40 equation in the model, so ys(50) and ys(80) are auxiliary equations (as the steady state file suggests). There should not be any division by zero. I can run the model smoothly using different versions of Taylor rules with various parameter specifications. Is there still something wrong with the way I specify the steady state?

Thank you.

Please use the current unstable version of Dynare, where a bug related to auxiliary variables when using instruments has been fixed. There you will get

[quote]evaluate_steady_state: The steady state file computation for the Ramsey problem resulted in NaNs.
evaluate_steady_state: The steady state was computed conditional on the following initial instrument values:
r 1.000000
evaluate_steady_state: The problem occured in the following equations:
Equation(s): 1, 2, 3, 4, 5, 6, 7, 10, 11, 14, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 38, 40,
evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.[/quote]

I manually executed the parameter definitions, the setting of r and then the equations in the steady_state_model-block using F9 in Matlab. I turns out that your steady state file is not properly recursive. You use

PHI2=(Y*UC)/(1-pi*beta*(PI_CPI^(varepsilon-1))); PHI1=((Y*UC)/(1-pi*beta*(PI_CPI^(varepsilon))))*(varepsilon/(varepsilon-1))*MC; 
but Y is only define later.

Thanks for the prompt response. I have now fixed the steady state block.

I am using the current unstable version of dynare for windows (i.e. dynare 2016-04-24 downloaded from here:dynare.org/snapshot/windows-zip/).

I’m not sure if that’s a problem but I also have the unstable 4.4.3 in the C drive. It used to be ok to have different versions simultaneously. I set the path in the folder of the most recent dynare version on the site.

I execute the parameter values, the instrument and the steady state model equations in this precise order using F9.

I then run dynare FINOP_RAMSEY.mod in the command window and get an identical outcome (i.e. lots of warnings and eventually the auxiliary variable problem).

Any further comments are greatly appreciated.

P.S. Apologies for the incompetence.

Check that you are using the correct version. The preprocessor should show

[quote]dynare FINOP_RAMSEY

Configuring Dynare …
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Using 64-bit preprocessor
Starting Dynare (version 2016-04-16).[/quote]

If the last line above says 4.4.3 then you are using the wrong path. I now get

evaluate_steady_state: Conditional on the following instrument values:
r 1.000000
evaluate_steady_state: the following equations have non-zero residuals:
Equation number 3: -2900105745041947900000.000000
Equation number 10: 6117457973423583000000.000000
Equation number 11: -4.324949
Equation number 14: 7.785978
Equation number 16: -2.646347
Equation number 21: 179102810608.442600
Equation number 24: -76677505772.973389
Equation number 29: -1.000000
Equation number 31: -1.000000
[/quote]

Thanks. I uninstalled 4.4.3 and I managed to get to the same stage as you did. I will try to workout the steady state once more, since it appears that something is going horribly wrong.

Its strange given that it runs with alternative policy rules. I’m probably still making instinctive errors given that I’m used to solving everything in the context of a zero inflation steady state.

So I managed to resolve most of the abnormalities in the steady state, but I find it hard to grind out this last step which is to do with the residual in the Euler equation:

evaluate_steady_state: The steady state file does not solve the steady state for the Ramsey problem. evaluate_steady_state: Conditional on the following instrument values: r 0.010050 evaluate_steady_state: the following equations have non-zero residuals: Equation number 16: -1.000000 Equation number 29: -1.000000

PI_CPI(+1)=beta*(UC(+1)/UC)*(1/LAMBDA); //(16) EULER EQUATION PI_CPI=CPI/CPI(-1); //(29) CPI INFLATION IDENTITY 

Where the instrument r=-log(beta)=~0.010050. The steady state of LAMBDA when r=-log(beta) is equal to beta itself and by definition UC(+1)=UC in the steady state, so I don’t see what could be wrong.

As usual, the files are attached below. Thank you.

Sidenote: I am not sure what you are doing. It seems the function you are solving numerically can be easily solved for inflation. So why do you use solver?
Now to the problem:
You have the function

r = (PI_CPI*LAMBDA)/beta; 
you want to solve. Setting r=0, we see that PI_CPI=0 is the solution. But

implies that

Well the reason I used csolve to begin with was because the example above used it and I wasn’t sure what it meant to specify the steady state conditional on the instruments. I thought that it was the only way, but I suppose the only reason it was used in the example was because there are multiple steady states of inflation unlike in my model.

I now realise that I don’t need the find_ file at all, but the initial value of the instrument must be very precise for dynare to solve for the steady state of the model. That is, initval r=-log(beta)=0.010050 does not solve the model and gives rise to small residuals:

evaluate_steady_state: The steady state for the Ramsey problem could not be computed. evaluate_steady_state: The steady state computation stopped with the following instrument values:: r 0.010050 evaluate_steady_state: The following equations have non-zero residuals: Equation number 17: -0.000079 Equation number 26: 0.000114 Equation number 29: -0.000171 Equation number 30: -0.000040

but r=-log(beta)=0.01005033585 does solve the model, because it is more accurate. However, to make it even more ironic, I am now struggling with the Blanchard Kahn conditions.

[code]Error using print_info (line 42)
Blanchard Kahn conditions are not satisfied: no stable equilibrium

Error in stoch_simul (line 94)
print_info(info, options_.noprint, options_);

Error in ramsey_policy (line 25)
info = stoch_simul(var_list);

Error in FINOP_RAMSEY (line 660)
ramsey_policy(var_list_);

Error in dynare (line 223)
evalin(‘base’,fname) ;[/code]

Which really puzzles me, because the model runs smoothly with other Taylor rules (the IRFs look smooth and non-oscillating). Is there anything in particular that I should keep in my when running ramsey_policy with regard to the time subscripts or predetermined variables that would otherwise not be a problem?

First off,

makes no sense. You are providing a steady state condition on the value of the instruments. Thus, it must work for any instrument! If it doesn’t, you are not taking the value of the instrument correctly into account. When you change the planner discount factor, your steady state file suddenly does not work anymore.

Regarding timing: the same rules apply as for stoch_simul. My guess is that there is an economic reason for the error message.

You may be right that my model contains an economic problem (I cannot guarantee that). For this reason, I took the most well known open economy framework (Gali & Monacelli(2005)) and wrote the mod file for the non-linear version of the model (i.e. I do not log-linearise by hand). I also include capital and define the net exports in a slightly different way, but these changes make no real difference to the end result. There are no further frictions.

I also wrote the .tex file (see pdf below and .tex code at the very bottom) with all the equilibrium conditions and detailed derivations of the conditional steady state. I suspect that the problem may arise do the misspecification of the price level steady state, but I’m not sure (which is why I keep pestering you on this blog post to begin with ).

In this case, the error message is different:

[code]
Warning: Rank deficient, rank = 0, tol = NaN.

In dyn_ramsey_static_dyn_ramsey_static_1 (line 152)
In dyn_ramsey_static>@(x)dyn_ramsey_static_1(x,M,options_,oo) (line 43)
In csolve (line 112)
In dyn_ramsey_static (line 58)
In resol (line 104)
In stoch_simul (line 83)
In ramsey_policy (line 25)
In GM_2005 (line 542)
In dynare (line 223)

evaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs.
i 0.010050
evaluate_steady_state: The problem occured in the following equations:
Equation(s): 1, 33, 34,
Error using print_info (line 140)
Ramsey: The steady state computation resulted in NaN in the static first order conditions for optimal policy
Error in stoch_simul (line 94)
print_info(info, options_.noprint, options_);
Error in ramsey_policy (line 25)
info = stoch_simul(var_list);
Error in GM_2008 (line 542)
ramsey_policy(var_list_);
Error in dynare (line 223)
evalin(‘base’,fname) ; [/code]

P.S. Apologies for yet another question on this, but this is really bothering me. Hopefully we can figure this out and you can put this example on github, so that others in the future would not have to struggle as much as I am.

GM_2005.pdf (208 KB)
GM_2005.mod (13.5 KB)

But do you know whether the Gali Monacelli model you enter works with steady state inflation, i.e. correctly accounts for a steady state nominal interest rate bigger than the real interest rate?

When running the model with a simple Taylor rule, the real interest rate is equal to the nominal interest rate in the zero inflation steady state (see code attached), where the gross real interest rate is defined by the usual Fisher equation:

RI=(exp(i))/PI_CPI;

And the resulting IRFs are smooth and well behaved.

Unless you were asking me if the model really works for anything other than the zero inflation steady state, to which the answer is probably - no, but I’m not quite sure how one should incorpotate that into the model and why that would be a sensible solution in this scenario. Is there a simple example available at hand?
GM_2005.mod (13.6 KB)

What I am saying: you use the nominal interest rate as your instrument. Optimal policy entails among other things selecting the steady state of the nominal interest rate. If this steady state is smaller or bigger than the real interest rate, this implies non-zero steady state inflation via the Fisher equation. If your model cannot handle this, you are in trouble.
Why this is sensible: when you look at simple classical monetary models with money in the utility function, the Friedman rule is optimal (0 nominal interest rate). As Schmitt-Grohe/Uribe have shown in a series of papers in the mid-2000s, in New Keynesian models with frictions, there are other mechanisms at work, but 0 inflation is typically not the efficient steady state. So you have to think about this possibility and potentially account for it in your model.

Hello again,

After months of focusing on other projects, I’ve decided to give this problem another go. I managed to specify the steady state of the model conditional on any rate of inflation/deflation (it works with stoch simul), but now I receive an error related to the planner discount:

[quote]dynare gm_ramsey.mod

Configuring Dynare …
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Local state space iteration (second order).
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.
[mex] Quasi Monte-Carlo sequence (Sobol).
[mex] Markov Switching SBVAR.

Using 64-bit preprocessor
Starting Dynare (version 2016-04-24).
Starting preprocessing of the model file …
WARNING: in the ‘steady_state_model’ block, variable ‘PI’ is not assigned a value
Substitution of endo leads >= 2: added 1 auxiliary variables and equations.
Substitution of endo lags >= 2: added 1 auxiliary variables and equations.
Found 34 equation(s).
Found 71 FOC equation(s) for Ramsey Problem.
Evaluating expressions…done
Computing static model derivatives:

• order 1
Computing dynamic model derivatives:
• order 1
• order 2
Computing static model derivatives:
• order 1
• order 2
• order 3
Processing outputs …
done
Preprocessing completed.

Warning: Some of the parameters have no value (optimal_policy_discount_factor) when using model_diagnostics. If
these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able
to solve the model…
Warning: Either you have not correctly initialized planner_discount or you are calling a command like steady or
stoch_simul that is not allowed in the context of ramsey_policy
MODEL_DIAGNOSTICS: The steady state cannot be computed
Warning: Rank deficient, rank = 33, tol = 2.498569e-12.

In dyn_ramsey_static_dyn_ramsey_static_1 (line 152)
In dyn_ramsey_static>@(x)dyn_ramsey_static_1(x,M,options_,oo) (line 43)
In csolve (line 60)
In dyn_ramsey_static (line 58)
In resol (line 104)
In stoch_simul (line 83)
In ramsey_policy (line 25)
In gm_ramsey (line 582)
In dynare (line 223)
Warning: Rank deficient, rank = 33, tol = 2.498583e-12.
In dyn_ramsey_static_dyn_ramsey_static_1 (line 152)
In dyn_ramsey_static>@(x)dyn_ramsey_static_1(x,M,options_,oo) (line 43)
In csolve (line 80)
In dyn_ramsey_static (line 58)
In resol (line 104)
In stoch_simul (line 83)
In ramsey_policy (line 25)
In gm_ramsey (line 582)
In dynare (line 223)
Warning: Rank deficient, rank = 33, tol = 2.498605e-12.
In dyn_ramsey_static_dyn_ramsey_static_1 (line 152)
In dyn_ramsey_static>@(x)dyn_ramsey_static_1(x,M,options_,oo) (line 43)
In csolve (line 112)
In dyn_ramsey_static (line 58)
In resol (line 104)
In stoch_simul (line 83)
In ramsey_policy (line 25)
In gm_ramsey (line 582)
In dynare (line 223)
Warning: Rank deficient, rank = 33, tol = 2.498605e-12.
In dyn_ramsey_static_dyn_ramsey_static_1 (line 152)
In dyn_ramsey_static>@(x)dyn_ramsey_static_1(x,M,options_,oo) (line 43)
In dyn_ramsey_static (line 70)
In resol (line 104)
In stoch_simul (line 83)
In ramsey_policy (line 25)
In gm_ramsey (line 582)
In dynare (line 223)
Error using print_info (line 54)
One of the eigenvalues is close to 0/0 (the absolute value of numerator and denominator is smaller than 1e-06!
If you believe that the model has a unique solution you can try to reduce the value of qz_zero_threshold.

Error in stoch_simul (line 94)
print_info(info, options_.noprint, options_);

Error in ramsey_policy (line 25)
info = stoch_simul(var_list);

Error in gm_ramsey (line 582)
ramsey_policy(var_list_);

Error in dynare (line 223)
evalin(‘base’,fname) ;[/quote]

Note that I am not using neither steady nor stoch_simul anywhere in my .mod file. It also gives rise to eigenvalue problems (none of which are encountered in stoch_simul with any Taylor rule), so I’m hoping this is something trivial.

Thanks ever so much in advance (.mod file is attached as usual).
gm_ramsey.mod (18.2 KB)

You cannot easily use the model_diagnostics-command (which calls steady) with Ramsey. That is where the message appears. Please focus on

Maybe that is already the reason.

Yes I have tried running it without the model diagnostics, but it still gives rise to 0/0 eigenvalue problem (but only with Ramsey!). Let me try to explain my approach a little bit better. PI stands of inflation. Inflation is the chosen instrument (replacing the Taylor rule). The steady state is conditional on the value of the instrument (meaning, it will work for any value of PI). When running the Ramsey version of this model, the initial value for PI is set in the initval block (as instructed before) and it is free to move around as the Ramsey algorithm sees fit (with a Taylor rule, it is specified in the steady_state_model block). Any further comments would be much appreciated.