Dear jpfeifer,
As I said to my latest post, I managed to load the parameter values from matlab to dynare. However now I face another problem. In the mod-file, I use the initvals; to set the steady state (that is as all variables are zero as the model is log-linearised by hand). When, I run dynare, while the parameter values are loaded correctly from the m-file, (I check this on the right hand side of the screen), I get the following message:
Error using print_info (line 80)
The steady state contains NaN or Inf
Error in resid (line 112)
print_info(info,options_.noprint, options_)
Error in NK_f3f (line 483)
resid(1);
Error in dynare (line 180)
evalin(‘base’,fname) ;
I run the model diagnostics and it says that model diagnostic can’t obtain the steady state!
However, I created another mod-file in which I set the parameter values manually (copied from the m-file) and the model runs!!
Any indication on where the problem is ?
I copy the mod-file and then the dedicated steady-state file, thank you very much in advance.
mod-file:
%variables
var
y %output tilde, where tilde is the gap from the natural rate
k %capital tilde
psi %quality of capital
r %real interest rate
rn %natural interest rate
Pi %inflation
a %productivity
y_f %natural level of output
k_f %natural level of capital
q %price of capital
q_f
inv %investment tilde
inv_f %natural level of investments
theta_hat %leverage ratio
nw %net worth
s_p %total securities tilde
s
v_hat
mu_hat
Omega_hat
r_k
z_hat
z_fhat
s_g
d_hat
varrho_hat
phi_ct
qnom
theta_fhat %leverage ratio
nw_f %net worth
s_fp %total securities tilde
s_f
v_fhat
mu_fhat
Omega_fhat
r_fk
s_fg
d_fhat
varrho_fhat
phi_fct
spread_t;
varexo
e_a %stochastic component of productivity
e_psi; %stochastic component of quality of capital
parameters
beta %static discount factor
alpha %capital share
varphi %Frisch inverse elasticity of labour
delta %depreciation of capital
gamma %elasticity of substitution among the differentiated goods (to match the markup)
M %markup
chi %parameter in convex adjustment cost function
Psi %steady-state of quality of capital shock
A %steady-state of productivity shock
Q %price of new-capital good (tobin’s q) steady-state, calculated from capital good producers optimal decision
phi %price flexibility value of real marginal cost (inverse of mark-up)
omega %degree of nominal price rigidity, to match quarterly data
rho_a %degree of autocorrelation, productivity shock
rho_psi %degree of autocorrelation, capital quality shock
sigma %survival rate of bankers
xi %transfer to entering bankers, perfect interbank
lambda %fraction of divertable assets
theta %levarage ratio, fixed according Gerlter Kiyotaki/ Gertler Karadi
R %real interest rate steady state
Qnom %from fischer equation, steady state value of nominal interest rate determination
Omega
mu %excess value
V
R_k %steady state value of intrabanking rate
Z %steady state value of Z
yk %ratios useful to calculate the steady state of quantity variables (like RBC)
ck
N %steady state of employment
K %steady state of capital
Y %steady state of output
C %steady state of consumption
S_p %steady state of private securities
S_g
S
NW %steady state of net worth
I %steady state of investments
D %steady state of deposits
rho_q %smoothing parameter of interest rate
kappa_pi %taylor rule weight on inflation
kappa_y %taylor rule weight on output
kappa_varrho %credit policy parameter
kappa_varrhof %credit policy parameter
varrho %steady state of credit policy tool
kappa_i
kappa_k
kappa_yi
kappa_yk
delta_1
delta_2
delta_3
delta_4
delta_5
delta_6
delta_7
delta_8
delta_9
delta_10
delta_11
delta_12
delta_13
alpha_1
alpha_2
alpha_3
delta_p %elasticity of inflation wrt the real marginal cost
nwk
dk
spread;
%Parameter values
load my_parameters.mat
model (linear);
%standard equations of NK with capital
%spread
spread_t=r_k-r;
%dynamic IS with capital (deviations from natural rate)
y=y(+1)-I/Y*(inv(+1)-inv)-(r - rn);
%natural interest rate
rn=y_f(+1)-y_f- I/Y*(inv_f(+1)-inv_f);
%flexible price equilibrium
0=-(((alpha+varphi)/(1-alpha))+(Y/C))*y_f + (I/C)inv_f + ((alpha(1+varphi))/(1-alpha))*k_f(-1) + ((1+varphi)/(1-alpha))*a;
%NKPC with capital (deviations from natural rate)
Pi=betaPi(+1) + delta_p(((Y/C)+((alpha+varphi)/(1-alpha)))*y - (I/C)inv - ((alpha(1+varphi))/(1-alpha))*k(-1));
%Fischer equation
r=qnom - Pi(+1);
%Interest rate rule(Taylor), characterisation of monetary policy
qnom=rho_qqnom(-1) + (1-rho_q)(kappa_piPi + kappa_yy + kappa_iinv + kappa_kk);
%law of motion of capital efficient
inv_f=(1/delta)*(k_f-(1-delta)*k_f(-1)-psi(+1));
inv=(1/delta)*k-((1-delta)/(delta))*k(-1);
%AR(1) technology shock
a=rho_a*a(-1)-e_a;
%asset price determination
q=chi*(inv-inv(-1))-betachi(inv(+1)-inv);
q_f=chi*(inv_f-inv_f(-1))-betachi(inv_f(+1)-inv_f);
%Demand for total bank assets
q+s=phi_ct+nw;
phi_ct=theta_hat+((varrho)/(1-varrho))*varrho_hat;
q_f + s_f=phi_fct + nw_f;
phi_fct=theta_fhat+((varrho)/(1-varrho))*varrho_fhat;
%determination of gross earnings from capital
z_hat=(Y/C+((1+varphi)/(1-alpha)))*y-(I/C)inv-((1+(alphavarphi))/(1-alpha))*k(-1);
z_fhat=y_f-k_f(-1);
%determination of leverage ratio net of interbank borrowing, theta_hat
theta_hat=v_hat+(mu/(lambda-mu))*mu_hat;
theta_fhat=v_fhat+(mu/(lambda-mu))*mu_fhat;
%linearity condition 1
v_hat=Omega_hat(+1);
v_fhat=Omega_fhat(+1);
%linearity condition 2
mu_hat=((OmegabetaR_k)/mu)r_k-(((OmegabetaR)/mu)+1)r+Omega_hat(+1);
mu_fhat=((OmegabetaR_k)/mu)r_fk-(((Omegabeta*R)/mu)+1)*r+Omega_fhat(+1);
%marginal value of net worth
Omega_hat=((sigmaV)/Omega)v_hat+((sigmathetamu)/Omega)(theta_hat+mu_hat);
Omega_fhat=((sigmaV)/Omega)v_fhat+((sigmathetamu)/Omega)(theta_fhat+mu_fhat);
%gross rate of return on bank assets
r_k = psi(+1)-q+(Z/R_k)*z_hat(+1)+((1-delta)/R_k)*q(+1);
r_fk = psi(+1)-q_f+(Z/R_k)*z_fhat(+1)+((1-delta)/R_k)*q_f(+1);
%Total securities on investing and non investing islands
s=delta*inv+(1-delta)k(-1);
s_f=deltainv_f+(1-delta)*k_f(-1);
%deposits
d_hat=(QS/D)(q+s_p)-(NW/D)nw;
d_fhat=(QS/D)*(q_f+s_fp)-(NW/D)*nw_f;
%law of motion of net worth
nw=((sigma+xi)/NW)(Zz_hat+(1-delta)Qq+(Z+(1-delta)Q)PsiS(psi+s_p(-1)))-((sigmaRD)/NW)(r(-1)+d_hat(-1));
nw_f=((sigma+xi)/NW)(Zz_fhat+(1-delta)Qq_f+(Z+(1-delta)Q)PsiS(psi+s_fp(-1)))-((sigmaRD)/NW)(rn(-1)+d_fhat(-1));
%credit policy
s_g= varrho_hat + s;
s=(S_p/S)*s_p+(S_g/S)s_g;
varrho_hat=kappa_varrho(r_k-r);
s_fg=varrho_fhat + s_f;
s_f=(S_p/S)*s_fp+(S_g/S)s_fg;
varrho_fhat=kappa_varrhof(r_fk-rn);
%AR(1) quality of capital shock
psi=rho_psi*psi(-1)-e_psi;
end;
initval;
y=0; %output tilde, where tilde is the gap from the natural rate
k=0; %capital tilde
psi=0; %quality of capital
r=0; %real interest rate
rn=0; %natural interest rate
Pi=0; %inflation
qnom=0; %nominal interest rate
a=0; %productivity
y_f=0; %natural level of output
k_f=0; %natural level of capital
q=0; %price of capital
q_f=0;
inv_f=0; %natural level of investments
inv=0;
theta_hat=0; %leverage ratio
nw=0; %net worth
s_p=0; %private securities
s=0;
v_hat=0;
mu_hat=0;
Omega_hat=0;
r_k=0;
z_hat=0;
z_fhat=0;
s_g=0;
d_hat=0;
varrho_hat=0;
spread_t=0;
phi_ct=0;
theta_fhat=0;
nw_f=0;
s_fp=0;
s_f=0;
v_fhat=0;
mu_fhat=0;
Omega_fhat=0;
r_fk=0;
s_fg=0;
d_fhat=0;
varrho_fhat=0;
phi_fct=0;
end;
resid(1);
steady;
check;
shocks;
var e_a;
stderr 0;
var e_psi;
stderr 0.05;
var e_a, e_psi= 00.06240.05;
end;
check;
stoch_simul(order=1,nomoments,periods=3000,irf=50)y Pi k inv q r_k r spread_t nw theta_hat s s_p s_g d_hat qnom;
Dedicated steady-state-m-file
function [ys,check] = NK_f3f_steadystate(ys,exo);
% function [ys,check] = NK_f3f_steadystate(ys,exo)
% computes the steady state for the NK_baseline.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 fpr 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)
% initialize indicator
check=0;
x0 =[4; 0.003; 5; 1.025; 0.0025; 10;];
options = optimset(‘TolFun’,1e-8,‘TolX’,1e-8,‘MaxIter’, 5000,‘MaxFunEvals’, 5000, ‘Display’,‘final’);
=fsolve(@fun_NK_f3f,x0,options);
nwk=x(1);
mu=x(2);
Omega=x(3);
R_k=x(4);
spread=x(5);
beta=0.99; %static discount factor
R=1/beta; %euler equation
sigma=0.97; %survival rate of bankers
xi=0.003; %transfer to entering bankers, perfect interbank
lambda=0.381; %fraction of divertable assets
theta=1/nwk;
mu= max(0,lambda-(Omega*nwk));
Qnom=R-1; %Fischer equation
alpha=0.33; %capital share
varphi=2; %Frisch inverse elasticity of labour
delta=0.025; %depreciation of capital
gamma=6; %elasticity of substitution among the differentiated goods (to match the markup)
M=gamma/(gamma-1); %markup
omega=0.75; %degree of nominal price rigidity, to match quarterly data
delta_p=((1-omegabeta)(1-omega)/(omega)); %elasticity of inflation wrt the real marginal cost
%steady-state values
chi=1; %parameter in convex adjustment cost function
Psi=1; %steady-state of quality of capital shock
A=1; %steady-state of productivity shock
Q=1; %price of new-capital good (tobin’s q) steady-state, calculated from capital good producers optimal decision
phi=1/M; %price flexibility value of real marginal cost (inverse of mark-up)
V=Omega;
Z=(R_k - (1-delta))Q;
yk=(1/(alphaphi))Z;
ck=yk - delta;
N=(phi(1-alpha)yk(ck)^(-1))^(1/(1+varphi));
K=N*(yk)^((-1/(1-alpha)));
I=deltaK;
C=ckK;
Y=ykK;
spread=R_k-R;
S=K;
NW=nwkK;
dk=1-nwk;
D=dk*K;
kappa_pi=1.5;
kappa_y=0.5/4;
kappa_i=0;
kappa_k=0;
kappa_yi=0;
kappa_yk=0;
kappa_varrho=50;
kappa_varrhof=0;
rho_a=0.95;
rho_psi=0.75;
rho_q=0.2;
varrho=0.1;
S_p=(1-varrho)*S;
S_g=S-S_p;
delta_1 = (gamma/2)(delta_p/(1-delta_p));
delta_2 = (1/2)(Y/C)(((alpha+varphi)/(1-alpha)));
delta_3 = (1/2)(IY)/(C^2);
delta_4 = (1/2)((1+varphi)/(1-alpha))(alpha^2)(Y/C);
delta_5 = (alphaY/C)((1+varphi)/(1-alpha));
delta_6 = ((IY)/(C^2));
delta_7=delta_5(1/(1-delta));
delta_8=delta_5*(delta/(1-delta));
delta_9=delta_6*(alpha/(1-delta));
delta_10=delta_6*((alphadelta)/(1-delta));
delta_11=delta_4(1/((1-delta)^2));
delta_12=2delta_4((delta/((1-delta)^2)));
delta_13=delta_4*(((delta^2)/((1-delta)^2)));
alpha_1=delta_3+delta_13;
alpha_2=delta_8-delta_6;
alpha_3=delta_6+delta_10;
save my_parameters.mat beta alpha varphi delta gamma M Psi A Q phi omega rho_a rho_psi sigma xi lambda theta R Qnom Omega V R_k Z yk ck N K Y C S_p S_g S NW I D rho_q kappa_pi kappa_y kappa_varrho kappa_varrhof varrho kappa_i kappa_k kappa_yi kappa_yk delta_1 delta_2 delta_3 delta_4 delta_5 delta_6 delta_7 delta_8 delta_9 delta_10 delta_11 delta_12 delta_13 alpha_1 alpha_2 alpha_3 delta_p nwk dk spread
end