Ramsey policy steady state: csovle

Hi,
I am solving a Ramsey problem in NK model .I now get the following error message:

Subscripted assignment dimension mismatch.
Error in csolve (line 80)
grad(:,i) = (feval(FUN,x+tvec(:,i),varargin{:})-f0)/delta;
Error in nk_commitment_ss (line 2)
x =
csolve(@nk_commitment,x0,[],1e-8,100,r,betta,omegga,fi,siggma,etta,xi,epsion,thetta,tau_n,tau_c);
Error in nk_commitment_steadystate (line 38)
x = nk_commitment_ss(x0,r,betta,omegga,fi,siggma,etta,xi,epsion,thetta,tau_n,tau_c);
Error in evaluate_steady_state_file (line 52)
[ys,check] = h_steadystate(ys_init, exo_ss);
Error in evaluate_steady_state (line 212)
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,
options,steadystate_check_flag);
Error in resol (line 104)
[dr.ys,M.params,info] =
evaluate_steady_state(oo.steady_state,M,options,oo,~options.steadystate.nocheck);
Error in check (line 73)
[dr,info,M,options,oo] = resol(1,M,options,oo);
Error in nk_commitment (line 286)
oo_.dr.eigval = check(M_,options_,oo_);
Error in dynare (line 235)

Please use the most recent Dynare version. It will tell you

The steadystate file did not compute the steady state

Your steady state file for Ramsey is wrong. It needs to take the instrument as given, but you set the instrument to

r=1/betta-1;

You would need something along the lines of

function [ys,check] = nk_commitment_steadystate(ys,exo)
% function [ys,check] = nk_commitment_steadystate(ys,exo)
% computes the steady state for the nk.mod and uses a numerical
% solver to do so
% Inputs: 
%   - ys        [vector] vector of initial values for the steady state of
%                   the endogenous variables
%   - exo       [vector] vector of values for the exogenous variables
%
% Output: 
%   - ys        [vector] vector of steady state values for the the endogenous variables
%   - check     [scalar] set to 0 if steady state computation worked and to
%                    1 of not (allows to impos restriction on parameters)

global M_ 

% get value of the instrument
NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically

for ii = 1:NumberOfEndogenousVariables
  varname = deblank(M_.endo_names(ii,:));
  eval([varname '= ys(' int2str(ii) ') ;']);
end

% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
  paramname = deblank(M_.param_names(ii,:));
  eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
% initialize indicator
check = 0;


%% Enter model equations here

options=optimset(); % set options for numerical solver

% r=1/betta-1;

A=1;
x0=[1,1,1,1,1];
x = nk_commitment_ss(x0,r,betta,omegga,fi,siggma,etta,xi,epsion,thetta,tau_n,tau_c);
pi=x(1);
pi_star=x(2);
w=x(3);
v=x(4);
N=x(5);
mc=w;
Y=A*N/v;
G=omegga*Y;
C=Y-G;
x1=1/(1-fi*betta)*C^(-siggma)*mc*Y;
x2=1/(1-fi*betta)*C^(-siggma)*Y;

%% end own model equations

for iter = 1:length(M_.params) %update parameters set in the file
  eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names(iter,:) ';' ])
end

for ii = 1:NumberOfEndogenousVariables
  varname = deblank(M_.endo_names(ii,:));
  eval(['ys(' int2str(ii) ') = ' varname ';']);
end
1 Like

I see.
Should I give an initial value to the instrument?
If so, how to do?
Thanks in advanced

Yes, you should, via initval

After I comment out the instrument, and adding initval-block in .mod file,

the error message reads as
Undefined function or variable ‘r’.
Error in nk_commitment_steadystate (line 38)
x = nk_commitment_ss(x0,r,betta,omegga,fi,siggma,etta,xi,epsion,thetta,tau_n,tau_c);
Error in evaluate_steady_state_file (line 52)
[ys,check] = h_steadystate(ys_init, exo_ss);
Error in evaluate_steady_state (line 212)
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,
options,steadystate_check_flag);
Error in resol (line 104)
[dr.ys,M.params,info] =
evaluate_steady_state(oo.steady_state,M,options,oo,~options.steadystate.nocheck);
Error in check (line 73)
[dr,info,M,options,oo] = resol(1,M,options,oo);
Error in nk_commitment (line 298)
oo_.dr.eigval = check(M_,options_,oo_);
Error in dynare (line 235)
evalin(‘base’,fname) ;

Please follow my code above where I already solved that issue. But the steady state is still not correct.

Thanks for your reply.

I follow your code, using Dynare 4.5.7, but it didn’t work. The error message is

Undefined operator ‘’ for input arguments of type ‘embedded.fi’.

Error in csolve (line 90)
dx0=-grad\f0;

Error in nk_commitment_ss (line 2)
x =
csolve(@nk_commitment,x0,[],1e-8,100,pi,betta,omegga,fi,siggma,etta,xi,epsion,thetta,tau_n,tau_c);

Error in nk_commitment_steadystate (line 47)
x = nk_commitment_ss(x0,pi,betta,omegga,fi,siggma,etta,xi,epsion,thetta,tau_n,tau_c);

Error in evaluate_steady_state_file (line 52)
[ys,check] = h_steadystate(ys_init, exo_ss);

Error in evaluate_steady_state (line 212)
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,
options,steadystate_check_flag);

Error in resol (line 104)
[dr.ys,M.params,info] =
evaluate_steady_state(oo.steady_state,M,options,oo,~options.steadystate.nocheck);

Error in check (line 73)
[dr,info,M,options,oo] = resol(1,M,options,oo);

Error in nk_commitment (line 298)
oo_.dr.eigval = check(M_,options_,oo_);

Error in dynare (line 235)
evalin(‘base’,fname) ;

When I code nk_try.m file to call csolve in nk_commitment_ss.m file, it works well, I got all steady state values of endogenous variables.

nk_commitment_ss.m (628 Bytes)

nk_try.m (447 Bytes)

Sorry, I find to conflict the parameter fi in my .mod file with buildin function in matlab.

Now, It had tell me:
The steadystate file did not compute the steady state.

So, I will check carefully the typo in my steady state file.

Thanks again!

Hi guys,

I have gone through the messy algebra and expressed everything as a function of N in the following auxiliary Matlab function nk_commitment_ss.m:

function N = nk_commitment_ss(N0,A,v,w,omegga,siggma,xi,etta,tau_n,tau_c)
N = csolve(@nk_commitment,N0,[],1e-8,100,A,v,w,omegga,siggma,xi,etta,tau_n,tau_c);
end

function F = nk_commitment(N,A,v,w,omegga,siggma,xi,etta,tau_n,tau_c)

F=xi*N^etta*v^(-siggma)-(1-tau_n)/(1+tau_c)*((1-omegga)*A*N)^(-siggma)*w;

end

My .mod file is

var C r pi N w mc A Y v pi_star x1 x2 G;

varexo e_a e_r;

parameters omegga betta phhi siggma etta xi epsion thetta rho_a rho_r fi_pi fi_y tau_n tau_c;

omegga=0.2;
betta=0.99;
phhi=0.25;
siggma=1;
etta=1;
xi=1;
epsion=3;
thetta=1;
rho_a=0.95;
rho_r=0.9;
fi_pi=1.5;
fi_y=0.7;
tau_n=0.05;
tau_c=0.15;


model;
C^(-siggma)=betta*C(+1)^(-siggma)*(1+r)*(1+pi(1))^(-1);
xi*N^etta=(1-tau_n)/(1+tau_c)*C^(-siggma)*w;
mc=w/A;
C+G=Y;
G=omegga*Y;
Y=A*N/v;
v=(1-phhi)*(1+pi_star)^(-epsion)*(1+pi)^epsion+(1+pi)^epsion*phhi*v(-1);
(1+pi)^(1-epsion)=(1-phhi)*(1+pi_star)^(1-epsion)+phhi;
1+pi_star=epsion/(epsion-1)*(1+pi)*x1/x2;
x1=C^(-siggma)*mc*Y+phhi*betta*(1+pi(1))^epsion*x1(1);
x2=C^(-siggma)*Y+phhi*betta*(1+pi(1))^(epsion-1)*x2(1);
A=A(-1)^rho_a*exp(e_a);
r=(1-rho_r)*steady_state(r)+rho_r*r(-1)+(1-rho_r)*(fi_pi*(pi-steady_state(pi))+fi_y*log(Y/steady_state(Y)))+e_r;
end;


initval;
r=0.1111;
pi=betta*(1+r)-1;
A=1;
pi_star=(((1+pi)^(1-epsion)-phhi)/(1-phhi))^(1/(1-epsion))-1;
mc=(epsion-1)/epsion*(1+pi_star)/(1+pi)*(1-betta*phhi*(1+pi)^epsion)/(1-betta*phhi*(1+pi)^(epsion-1));
v=(1-phhi)*(1+pi_star)^(-epsion)*(1+pi)^(epsion)/(1-phhi*(1+pi)^(epsion));
w=mc;
N=nk_commitment_ss(1,A,v,w,omegga,siggma,xi,etta,tau_n,tau_c);
Y=A*N/v;
G=omegga*Y;
C=Y-G;
x1=C^(-siggma)*mc*Y/(1-phhi*betta*(1+pi)^epsion);
x2=C^(-siggma)*Y/(1-phhi*betta*(1+pi)^(epsion-1));
end;

/*
steady_state_model;
pi=betta*(1+r)-1;
A=1;
pi_star=(((1+pi)^(1-epsion)-phhi)/(1-phhi))^(1/(1-epsion))-1;
mc=(epsion-1)/epsion*(1+pi_star)/(1+pi)*(1-betta*phhi*(1+pi)^epsion)/(1-betta*phhi*(1+pi)^(epsion-1));
v=(1-phhi)*(1+pi_star)^(-epsion)*(1+pi)^(epsion)/(1-phhi*(1+pi)^(epsion));
w=mc;
N=nk_commitment_ss(1,A,v,w,omegga,siggma,xi,etta,tau_n,tau_c);
Y=A*N/v;
G=omegga*Y;
C=Y-G;
x1=C^(-siggma)*mc*Y/(1-phhi*betta*(1+pi)^epsion);
x2=C^(-siggma)*Y/(1-phhi*betta*(1+pi)^(epsion-1));
end;
*/
resid;
check;
steady;

shocks;
var e_a;
stderr 0.01;
end;

stoch_simul(nograph);

%planner_objective C^(1-siggma)/(1-siggma)-xi*N^(1+etta)/(1+etta);

%ramsey_policy(planner_discount=0.99,order=1,instruments=(r));

When I run the code in stoch_simul(), it works well.

But commented out the monetary policy , monetary shock, steady; and stoch_simul; , I run ramsey_policy, the error:

Residuals of the static equations:

Equation number 1 : NaN
Equation number 2 : 0
Equation number 3 : NaN
Equation number 4 : -0.82997
Equation number 5 : 0
Equation number 6 : 0
Equation number 7 : NaN
Equation number 8 : 0
Equation number 9 : NaN
Equation number 10 : 0
Equation number 11 : NaN
Equation number 12 : NaN
Equation number 13 : 0


Error using print_info (line 76)
The steadystate file did not compute the steady state
Error in check (line 76)
    print_info(info, 0, options);
Error in nk_commitment (line 299)
oo_.dr.eigval = check(M_,options_,oo_);
Error in dynare (line 235)
evalin('base',fname) ; 

Many thanks,