Issue with the Kalman filter

Hi all,

I am very new to Dynare, but I have studied the program to the point where I have written a very simple model. This model seems to function well (steady states and simulation work fine), but the estimation of the model persistently fails with the error message:
“The forecast error variance in the multivariate Kalman filter became singular.”

I have tried several things to round the issue, but with very little success.
All tips to solve as well as explanations why this error rises would be very very much appreciated!

Basic_model.mod (1.1 KB)
Model_estimation.mod (2.0 KB)
data.xlsx (11.6 KB)

The problem is known as “stochastic singularity”, which happens if a linearized model implies an exact linear combination between observables. That in turn means that the density of observing that variables is either 1 (the exact linear combination in the model holds in the data; rarely the case) or 0 (the exact linear combination does not hold; the typical case). As you can imagine with a log density of minus infinity, estimation will not work.

You have in your model

exp(y_tilde) = exp(k_tilde)^(alph);

But you observe k and y. That’s where the problem comes from. The model says that the ratio of y and k is a constant \alpha. Plotting the ratio shows that this is not the case in the data:

image

Hello professor Pfeifer and thank you very much for your prompt reply!

I do understand the issue now, but I still don’t know how to get around the problem. I have tried e.g.:

a) To use only one observable variable in the estimation (Dynare shouldn’t be able to decide if the data contains exact linear combination or not if there is only one observable)
→ In case a) I still get the error message and the estimation does not work.

b) Adding a measurement error to the observables to tell Dynare that the linear combination does not hold in the observed data when there are more than one observed variables
→ In case b) the estimation goes through, but all variation is accounted to the measurement errors. Furthermore, the posteriors of the estimations appear to coincide with the prior distributions since everything is accounted to the measurement error.

c) Adding new shocks, e.g. TFP shock to production function that follows AR1-structure, to break an exact linear combination.
→ Still, Dynare does not compute the simulation and the same error message come up.

Is there something else that I could try or am I missing something / doing some elementary mistakes in the code/data?

Another question that has puzzled me regarding Dynare:
I would prefer if the shocks on b-variables could only get values from the positive side of the normal distribution). How does Dynare/estimation react if I force the normally distributed shocks to follow some Gamma distribution by squaring the shocks? Or is there some other way to force the shocks positive (that would also work in the estimation)?

  1. Use
stoch_simul(irf=0,order=1);

to verify that all of your variables are constant as they are not affected by the shocks. That explains the error message.
2. Regarding non-normal shocks, first have a look at previous posts like Models with non-normal shocks (Non-linear transformation of shocks)

Oh, there was an elementary mistake with the shock process!
Thank you very much for pointing out the two problems I had and for nudging me back on track! I will go through earlier chats regarding non-normal shocks too.

Hi dear prof,
I have the same problem :initial_estimation_checks:: The forecast error variance in the multivariate Kalman filter became singular.
initial_estimation_checks:: This is often a sign of stochastic singularity, but can also sometimes happen by chance
initial_estimation_checks:: for a particular combination of parameters and data realizations.
initial_estimation_checks:: If you think the latter is the case, you should try with different initial values for the estimated parameters. these are my errors but i don’t know how to solve it could you please help me out?

Uploading: untitled.mod…
data.mat (2.2 KB)

this is the text:

%define whether to use interest rate or money growth rate rule
@#define money_growth_rule=0

var pi1 {\pi} (long_name=‘inflation’)
y_gap {\tilde y} (long_name=‘output gap’)
y_nat {y^{nat}} (long_name=‘natural output’) //(in contrast to the textbook defined in deviation from steady state)
y {y} (long_name=‘output’)
g {g} (long_name=‘output_growth’)
r_nat {r^{nat}} (long_name=‘natural interest rate’)
r_real {r^r} (long_name=‘//real interest rate’)
i1 {i} (long_name=‘nominal interrst rate’)
n {n} (long_name=‘hours worked’)
m_real {m-p} (long_name=‘real money stock’)
m_growth_ann {\Delta m} (long_name=‘money growth annualized’)
@#if money_growth_rule==0
nu {\nu} (long_name=‘AR(1) monetary policy shock process’)
@#else
money_growth {\Delta m_q} (long_name=‘money growth’)
@#endif
a {a} (long_name=‘AR(1) technology shock process’)
r_real_ann {r^{r,ann}} (long_name=‘annualized real interest rate’)
i_ann {i^{ann}} (long_name=‘annualized nominal interest rate’)
r_nat_ann {r^{nat,ann}} (long_name=‘annualized natural interest rate’)
pi_ann {\pi^{ann}} (long_name=‘annualized inflation rate’)
z
;

varexo eps_a {\varepsilon_a} (long_name=‘technology shock’)
@#if money_growth_rule==0
eps_nu {\varepsilon_\nu} (long_name=‘monetary policy shock’)
@#else
eps_m {\varepsilon_\m} (long_name=‘money growth rate shock’)
@#endif
eps_z {\varepsilon_\z} (long_name=‘money growth rate shock’)
;

parameters alppha {\alppha} (long_name=‘capital share’)
betta {\beta} (long_name=‘discount factor’)
rho_a {\rho_a} (long_name=‘autocorrelation technology shock’)
@#if money_growth_rule==0
rho_nu {\rho_{\nu}} (long_name=‘autocorrelation monetary policy shock’)
@#else
rho_m {\rho_{m}} (long_name=‘autocorrelation monetary growth rate shock’)
@#endif
siggma {\sigma} (long_name=‘log utility’)
phi {\phi} (long_name=‘unitary Frisch elasticity’)
phi_pi {\phi_{\pi}} (long_name=‘inflation feedback Taylor Rule’)
phi_y {\phi_{y}} (long_name=‘output feedback Taylor Rule’)
eta {\eta} (long_name=‘semi-elasticity of money demand’)
epsilon {\epsilon} (long_name=‘demand elasticity’)
theta {\theta} (long_name=‘Calvo parameter’)
;
%----------------------------------------------------------------
% Parametrization, p. 52
%----------------------------------------------------------------
siggma = 1;
phi=1;
phi_pi = 1.5;
phi_y = .5/4;
theta=2/3;
@#if money_growth_rule==0
rho_nu =0.5;
@#else
rho_m=0.5;

@#endif
rho_a = 0.9;
betta = 0.99;
eta =4;
alppha=1/3;
epsilon=6;
sig_z = 0.0109 ;
%----------------------------------------------------------------
% First Order Conditions
%----------------------------------------------------------------

model(linear);
//Composite parameters
#Omega=(1-alppha)/(1-alppha+alpphaepsilon); //defined on page 47
#psi_n_ya=(1+phi)/(siggma
(1-alppha)+phi+alppha); //defined on page 48
#lambda=(1-theta)(1-bettatheta)/thetaOmega; //defined on page 47
#kappa=lambda
(siggma+(phi+alppha)/(1-alppha)); //defined on page 49

//1. New Keynesian Phillips Curve eq. (21)
pi1=bettapi1(+1)+kappay_gap;
//2. Dynamic IS Curve eq. (22)
y_gap=-1/siggma*(i1-pi1(+1)-r_nat)+y_gap(+1);
//3. Interest Rate Rule eq. (25)
@#if money_growth_rule==0
i1=phi_pipi1+phi_yy_gap+nu;
@#endif
//4. Definition natural rate of interest eq. (23)
r_nat=siggmapsi_n_ya(a(+1)-a);
//5. Definition real interest rate
r_real=i1-pi1(+1);
//6. Definition natural output, eq. (19)
y_nat=psi_n_yaa;
//7. Definition output gap
y_gap=y-y_nat;
//8. Monetary policy shock
@#if money_growth_rule==0
nu=rho_nu
nu(-1)+eps_nu;
@#endif
//9. TFP sh
a=rho_aa(-1)+eps_a;
//10. Production function (eq. 13)
y=a+(1-alppha)n;
//11. Money growth (derived from eq. (4))
m_growth_ann=4
(y-y(-1)-eta
(i1-i1(-1))+pi1);
//12. Real money demand (eq. 4)
m_real=y-etai1;
@#if money_growth_rule==1
//definition nominal money growth
money_growth=m_real-m_real(-1)+pi1;
//exogenous process for money growth
money_growth=rho_m
(money_growth(-1))+eps_m;
@#endif

//13. Annualized nominal interest rate
i_ann=4i1;
//14. Annualized real interest rate
r_real_ann=4
r_real;
//15. Annualized natural interest rate
r_nat_ann=4r_nat;
//16. Annualized inflation
pi_ann=4
pi1;
g = y - y(-1) + z;
z = eps_z ;

end;

%----------------------------------------------------------------
% define shock variances
%---------------------------------------------------------------

shocks;
@#if money_growth_rule==0
var eps_nu = 0.25^2; //1 standard deviation shock of 25 basis points, i.e. 1 percentage point annualized
@#else
var eps_m = 0.25^2; //1 standard deviation shock of 25 basis points, i.e. 1 percentage point annualized
@#endif
var eps_a = 1^2; //unit shock to technology
var eps_z = sig_z^2 ;

end;

%----------------------------------------------------------------
% steady states: all 0 due to linear model
%---------------------------------------------------------------
resid;
steady;
check;

%----------------------------------------------------------------
% generate IRFs, replicates Figures 3.1, p. 53 (interest rate rule)
% 3.3, p. 57 (money growth rule)
%----------------------------------------------------------------
@#if money_growth_rule==0
stoch_simul(order = 1,irf=15) y pi1 i1 ;
@#else
stoch_simul(order = 1,irf=15) y pi1 i1 ;
@#endif

shocks;
@#if money_growth_rule==0
var eps_nu = 0; //shut off monetary policy shock
@#else
var eps_m = 0; //shut off monetary policy shock
@#endif
var eps_a = 1^2; //unit shock to technology
var eps_z = sig_z^2 ;
end;

%----------------------------------------------------------------
% generate IRFs, replicates Figures 3.2, p. 55 (interest rate rule)
% 3.4, p. 59 (money growth rule)
%----------------------------------------------------------------
stoch_simul(order = 1,irf=15,irf_plot_threshold=0) y pi1 i1 n a ;
write_latex_dynamic_model;

varobs y i1 pi1;

% Load the data file (assuming ‘data.mat’ as an example filename)
% Make sure ‘data.mat’ contains a MATLAB table named ‘data’

% Define the estimated parameters
estimated_params;
betta, beta_pdf, 0.99, 0.02;
stderr eps_nu, normal_pdf, 0.01, inf;

stderr eps_a,0.4618,0.01,3,INV_GAMMA_PDF,0.1,2;

stderr eps_z,0.6090,0.01,3,INV_GAMMA_PDF,0.1,2;

end;
% Perform the estimation
%estimation(datafile=data, mode_compute=0, mh_replic=2000,
%mh_nblocks=2, mh_drop=0.1, mh_jscale=2.5, conf_sig=0.95, bayesian_irf, irf=20);

estimation(optim=(‘MaxIter’,200),datafile=data,mode_compute=0,
first_obs=1, presample=4,lik_init=2,prefilter=0,mh_replic=0,mh_nblocks=2,
mh_jscale=0.20,mh_drop=0.2, conf_sig=0.95, bayesian_irf,
irf=0, nograph, nodiagnostic, tex);

shock_decomposition y;

HI again, I solved the previous problem, but another one happened:Error using print_info
Blanchard & Kahn conditions are not satisfied: no stable equilibrium.

Error in DsgeSmoother (line 133)
print_info(info,options_.noprint, options_);

can you help me please why is this
Uploading: untitled.mod…
data.mat (2.2 KB)

untitled.mod (8.0 KB)

You need to set the diffuse_filter option of calib_smoother because the model has a unit root.

@vaheed We are trying to investigate the upload issues. Does the problem persist for you? If yes, could you please state your device/OS/browser?