I have quite an issue when performing the OLS estimation of two parameters (rho and e_a) in Dynare. The error tag says " Warning: The results below are most likely wrong!". Besides, dynare only finds the parameters’ estimate but not the stderr and t-stat (“NAN”). Here are my mod and data files.

DATAFILE - “mydata”:

dataset = [];
% dates in a vector
T = 1960:0.25:(1960+(length(dataset)-1)/4);
% selecting the 2nd column to select GDP
gross_y = dataset(:,2);
% Taking in logs
ln_y = log(gross_y);
% computing the slope of the growth of output
% Using OLS
X = [ones(length(ln_y),1) (1:length(ln_y))'];
OLS= X\ln_y; % OLS regression
trend_y = X*OLS;
gamma = 1+OLS(2);
% deviation from the trend
ln_gap = ln_y-trend_y;
% demeaning // removing the steady state
y = ln_gap-mean(ln_gap);

MOD FILE:

var c k y a;
varexo e_a;
parameters alpha beta delta gamma rho Css Kss Yss;
% Calibration
alpha = 0.40; % capital share in production
beta = 0.99; % discount factor
delta = 0.025; % depreciation rate
rho = 0.95; % shock autocorrelation
gamma = 1.005; % trend variable
% steady states
Kss = ((gamma/beta-(1-delta))/alpha)^(1/(alpha-1));
Css = Kss^alpha + (1-delta-gamma)*Kss;
Yss = Kss^alpha;
% Model
model;
% Budget constraint
c+(k*gamma)=(a*(k(-1)^alpha))+(1-delta)*k(-1);
% Euler equation
(1/c)=(beta/(gamma*c(+1)))*((alpha*a(+1)*(k^(alpha-1)))+(1-delta));
% Production function
y=a*(k(-1)^alpha);
% Positive productivity shock (negative if -e)
ln(a) = rho*ln(a(-1))+e_a;
end;
% Steady State
initval;
k= 50.11;
c=3.25;
y=4;
a=1;
end;
steady(maxit=1000);
check;
% shock calibration
shocks;
var e_a; stderr .007;
end;
% check the stability
check;
% perform stochastic simulations
stoch_simul(irf=0);
varobs y;
estimated_params;
stderr e_a, 0.007, 0, inf;
rho, 0.95, 0, 1;
end;
estimation (datafile=mydata);

There is actually the datafile (right before the mod file). I did not insert the data inside « dataset[] » as it would be unreadable for you. GDP data start from 1960 up to 2017.

Just so you know, I only have a problem when putting the model in a non linear form on Dynare. When I write the model in linear form, it works just fine.

Here are the tags that I get:

"POSTERIOR KERNEL OPTIMIZATION PROBLEM!
(minus) the hessian matrix at the “mode” is not positive definite!
=> posterior variance of the estimated parameters are not positive.
You should try to change the initial values of the parameters using
the estimated_params_init block, or use another optimization routine.
Warning: The results below are most likely wrong!

In dynare_estimation_1 (line 316)
In dynare_estimation (line 105)
In log_basicRBC_chap2_nonlinear (line 174)
In dynare (line 223)
Warning: Matrix is singular, close to singular or badly scaled. Results may be
inaccurate. RCOND = NaN.
In dynare_estimation_1 (line 339)
In dynare_estimation (line 105)
In log_basicRBC_chap2_nonlinear (line 174)
In dynare (line 223)

RESULTS FROM MAXIMUM LIKELIHOOD ESTIMATION
parameters
Estimate s.d. t-stat

rho 1.0000 NaN NaN

standard deviation of shocks
Estimate s.d. t-stat

e_a 0.0023 NaN NaN

Total computing time : 0h00m04s
Note: warning(s) encountered in MATLAB/Octave code"

Both versions are problematic. In the linear version, you do not handle parameter dependence correctly. That would be a problem if you estimate other parameters. In the nonlinear version, you are missing a proper observation equation. Your data is demeaned, but it is matched to the undemeaned variable y. You need

Thank you very much. I’ve always wondered whether to code in a non-linear way or linear way. What I understand from your statement is that coding in a non-linear way is better for handling parameter dependence than coding in a linear way.

I have other issues regarding my model. I’ve incorporated consumption data (in the datafile) and two other shocks, namely preference shock (epsilon_c) and public spending shock. I have issues when estimating the parameters with the file combining the productivity shock and the preference shock, and the file combining the productivity, preference and public spending shock. The file combining productivity and public spending shocks works just fine. I can’t find my mistake in the two files (basicRBC_nonlinear_ex2_outputpreference.mod and basicRBC_nonlinear_ex2_OSP.mod).

Here are my mod and data files. I’ve also attached the shocks specifications.

What is the problem you are experiencing? If it is just about the Hessian, try mode_compute=5 and consider moving to Bayesian estimation. ML often does not work well. Your rho_a is estimated to be very close to a unit root. That creates a problem when trying to compute the Hessian.

Dynare finds all the IRFs, steady states etc. My issue is when estimating the parameters via ML.
Dynare is giving me estimation tag errors for the “OSP” and “output preference” files:

POSTERIOR KERNEL OPTIMIZATION PROBLEM!
** (minus) the hessian matrix at the “mode” is not positive definite!** => posterior variance of the estimated parameters are not positive. You should try to change the initial values of the parameters using the estimated_params_init block, or use another optimization routine. Warning: The results below are most likely wrong! ** > In dynare_estimation_1 (line 316)
** In dynare_estimation (line 105)
** In basicRBC_nonlinear_ex2_outputpreference (line 210)**
** In dynare (line 223) **

MODE CHECK

Fval obtained by the minimization routine (minus the posterior/likelihood)): -1662.940406 Error using matlab.graphics.chart.primitive.Line/get Invalid or deleted object. Error in mode_check (line 183)
** line_color=get(fighandle,‘color’);** Error in dynare_estimation_1 (line 323)
** mode_check(objective_function,xparam1,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);**
** Error in dynare_estimation (line 105)**
** dynare_estimation_1(var_list,dname);** Error in basicRBC_nonlinear_ex2_outputpreference (line 210) oo_recursive_=dynare_estimation(var_list_); Error in dynare (line 223) evalin(‘base’,fname) ;

How do I move to Bayesian estimation? I’m very new to that topic.