Filter out cases where invalid starting value leads to NaN or Inf in Jac...
...obian.
Replaces cryptic meassage "Some element of Newton direction isn't finite. Jacobian maybe singular or there is a problem with initial values" with more expressive message. Sample mod file from the forum:
%-------------------------------------------------------------------------------------------
% The macroeconomic Effect of Non-Zero Trend Inflation
%-------------------------------------------------------------------------------------------
% endogenous variables
var
c %consumption
b %money demand shock
m %nominal balances
lambda %lagrange multiplier
r %nominal interest rate
pi %inflation rate
h %hours worked
i %real investment
k %capital stock
y %output
ys %aggregate output
s %aggregate prices indicator
q % real rental rate of capital
w % real wages
psi % real marginal cost
a %technology level
pstar %optimal price
x %price evolution indicator 1
z %price evolution price indicator 2;
%exogenous shocks
varexo er, ea, eb;
%model parameters
parameters beta, sigma, eta, alpha, theta, delta, phi, d, rhor, rhopi, rhoy, rhob, sigma_eb, rhoa, sigma_ea, sigma_er, ybar, pibar, Rs, As, Bs;
%---------------------calibration-------------------------------------------------------------------------------------
beta=0.99; %discount factor
sigma=0.25; %elasticity of substitution between consumption and real balances
eta=1.5; %
alpha=0.34; %elasticity of substitution between capital and hours worked
theta=0.01; %elasticity of substitution between types of differentiated intermediate goods
delta=0.025; %depreciation rate of capital
phi=10.0; %parameter of adjustment costs of investment
d=0.75; %calvo parameter
rhor=0.80; %the Taylor rule interest rate parameter
rhopi=1.50; %the Taylor rule inflation rate parameter
rhoy=0.20; %the Taylor rule output parameter
rhob=0.80; %money demand shock parameter
sigma_eb=0.01; %std.dev of money demand stochastic shock
rhoa=0.80; %technologic shock parameter
sigma_ea=0.01; %std.dev of the technologic shock
sigma_er=0.01; %std.dev of the monetary policy shock
ybar=0.7877; %steady state output
pibar=(1.0)^(1/4); %steady state price
Rs=pibar/beta;
As=1;
Bs=1;
model;
%---------FOC Households--------------------------------------------------------------------------------------
c^(-1/sigma)/(c^((sigma-1)/sigma)+(b^(1/sigma))*(m^((sigma-1)/sigma)))=lambda; %eq1
b^(1/sigma)*m^(-1/sigma)/(c^((sigma-1)/sigma)+(b^(1/sigma))*(m^((sigma-1)/sigma)))=lambda*(1-(1/r)); %eq2
lambda=beta*lambda(+1)*(r/(pi(+1))); %eq3
eta/(1-h)=lambda*w; %eq4
lambda*(1 + phi*((i/k(-1))-delta))=beta*lambda(+1)*(1+q(+1)-delta+(phi*((i(+1)/k)-delta)+(phi/2)*((i(+1)/k)-delta)^2)); %eq5
%-----------law of the accumilation of capital------------------------------------------------------------------
k=(1-delta)*k(-1)+i; %eq6
%-----------FOC firms-------------------------------------------------------------------------------------
ys=y*s; %eq7
ys=a*(k(-1)^(1-alpha))*(h^alpha); %eq8
q=(1-alpha)*psi*(ys/k(-1)); %eq9
w=alpha*psi*(ys/h); %eq10
y=c+k+(1-delta)*k(-1)+((phi/2)*(((i/k(-1))-delta)^2)*(k(-1))); %eq11
%-------------Taylor rule--------------------------------------------------------------
r=(Rs^(1-rhor))*(r(-1)^(rhor))*((pi/pibar)^(rhopi))*((y/ybar)^(rhoy))*exp(er); %eq12
%-----------------Shock---------------------------------------------------------------------------------
b=(b(-1)^(rhob))*(b(-2)^(rhob))*(Bs^(1-rhob))*exp(eb); %eq13
a=(As^(1-rhoa))*(a(-1)^(rhoa))*(a(+2)^(rhoa))*exp(ea); %eq14
%--------------------calvo pricing--------------------------------------------------------------------------
s=(1-d)*(pstar^(-theta))+d*(pi^(theta))*s(-1); %eq15
1=d*(pi^(theta-1))+(1-d)*(pstar^(1-theta)); %eq16
x=y*psi*(pstar(-1)^(-theta-1))+d*beta*(lambda(+1)/lambda)*((pstar/pstar(+1))^(-theta-1))*(pi(+1)^(theta))*x(+1); %eq17
z=y*(pstar(-1)^(-theta))+d*beta*(lambda(+1)/lambda)*((pstar/pstar(+1))^(-theta))*(pi(+1)^(theta-1))*z(+1); %eq18
x=((theta-1)/theta)*z; %eq19
end;
initval;
y=0.78;
c=0.64;
m=0.50;
i=0.14;
h=0.33;
w=1.45;
pi=1;
psi=0.87;
r=1;
a=0;
b=0;
s=1;
k=6.35;
q=0.035;
pstar=1.5;
end;
resid(1);
steady;
check;
shocks;
var er; stderr 0.4;
end;
stoch_simul(irf=20, AR=6) y c h i m w pi r;