Forecast error variance in multivariate Kalman Filter became singular

Hi there,

I am getting the following error when I try and estimate the attached model:

initial_estimation_checks:: The forecast error variance in the multivariate Kalman filter became
singular.

wsnff.mod (6.3 KB)
dsge_est1.xlsx (39.5 KB)
wagesub_stst1.mod (942 Bytes)

This seems strange because stochastic simulation runs fine on the calibrated model, and I can estimate the model if I drop one of the GDP related variables (i.e. Government investment or consumption for example). Also, estimation still doesn’t work when I initialize the Kalman Filter with the calibrated parameters. I don’t think there is a problem with the model- the model diagnostics all suggest the model is fine.

Just wondering if anyone had any tips on solving this problem? It would be nice to estimate the model with all of the components of closed economy GDP included if possible.

1 Like

Apologies, with correct files this time!
wsnff.mod (6.2 KB)
wagesub_stst1.mod (942 Bytes)
dsge_est1.xlsx (20.9 KB)

That is not feasible. See

Hi Professor- thanks for your response- There are an equal number of shocks and observable series in the model. That is not the problem. Adding more shocks does not solve the problem.
:smiley:

1 Like

Don’t focus on the number of shocks. The problem also arises when there is an exact linear combination of observables implied by the model. You wanted

That is an exact linear combination due to
Y=C+I+G
and explains why it works when you drop one of those.

2 Likes

Greetings, Prof. Pfifer.

I received the same error message as timxwatson and tried the same solution, and also tried to change the priors, but without success.

I’m trying to make a Bayesian estimation of Ascary and Ropelle’s (2012) version of Schmitt-Grohé, & Uribe (2005), medium-scale nonlinear new Keynesian model.

I was able to make the calibrated perfect foresight simulation successfully, but not the Bayesian estimation.

The original data I used for the observed variables was obtained from the Excel file provided by Smets and Wouters (2007). I made the linear detrending of the 7 variables and converted the basis of output and its compounds to a steady state real GDP of y = 2.9135, and for h (hours worked) the base was steady state h = 1. While SW used the growth rate for GDP and compounds, I used their real values detrended and converted to the steady state bases I used in my previous calibrated simulation.

I used the same shocks as in SW.

I tried Bayseian estimation with and without consumption as observed variables, but in both cases the error message was:

“The variation in prediction error in the multivariate Kalman filter has become singular.”

I tried to upload the code to this message, but this error message appeared:

“Sorry, it looks like something has gone wrong, the file you are trying to upload is 0 bytes. Please try again.”

However, the mod file I was trying to upload was the correct one, with 12 KB.

Without the codes it is impossible to tell.

I was not able to upload the mod file of the code. Here goes its content:

% The model replicates Ascari Ropele JMCB (2010), but using varobs and shocks from Smets and Wouters (2007).
% The model also uses Schmitt-Grohe and Uribe (2005) NBER WP 11417.
% Ascari and Ropele (2010) is a medium scale non log-linearized new Keynesian model. The model was used
% in simulations in the respective paper and in Ascari and Ropele (2012), using Christiano, Eichembaun and Evans (2005) calibration.
% As long as we know, neither Ascari and Ropele or any othe author have made a Bayseian estimation of those parameters, and
% this is the purpose of the current code.

%	The code uses 27 AR ENDOGENOUS VARIABLES + 7 variables of the autocorrelated processes for Bayesian estimation + 3 variables for simulations

var
u    	% capacity utilization
c    	% consumption
h    	% hours worked
invest    	% capital investment
k    	% capital stock
lamb  	% Lagrange multiplier household budget constraint
pi   	% gross quarterly inflation
w    	% real wage
mutil	% (inverse of) Lagrange multiplier labor supply AR (14)
q       % market value capital
rk      % rental price capital
div 	% dividends
f1      % term for recursive expression for wage
f2      % term for recursive expression for wage
wtil	% real wage optimizing firm
hd      % worker hours demanded
y    	% output
mc    	% real marginal cost
x1      % term for recursive expression for price
x2      % term for recursive expression for price
ptil	% relative price optimizing firm
s       % cross section price dispersion
stil	% cross section wage dispersion
tau     % lump sum tax
R       % nominal gross quarterly interest rate
g       % government spending
z       % Productivity
yd      % % deviation of y from new steady state
pi_y    % annual inflation (%)
pi_q    % quarterly inflation (%)



    zs  % productivity shock process
    bs  % risk premium shock process
    gs  % spending shock process
    qs  % investment shock process
    ms  % Monetary policy shock process
    spinf % price markup shock process
    sw  % wage markup shock process


;

% EXOGENOUS VARIABLES
varexo

    ez       ${\eta^a}$      (long_name='productivity shock')
    eb          ${\eta^b}$      (long_name='risk premium shock')
    eg          ${\eta^g}$      (long_name='Spending shock')
    eqs         ${\eta^i}$      (long_name='Investment-specific technology shock')
    em          ${\eta^m}$      (long_name='Monetary policy shock')
    epinf       ${\eta^{p}}$    (long_name='Price markup shock')
    ew          ${\eta^{w}}$    (long_name='Wage markup shock')

;


%	PARAMETERS

parameters
beta		% discount rate
b       	% habit parameter
phi0		% preference parameter 	labor
eta         % elasticity substitution differianted good
etatil		% elasticity substitution labor types
delt		% capital depreciation rate
kap         % investment adj cost function
gam1		% cap utilization function
gam2		% cap utilization function
alphtil		% Calvo prob not reset wages
chitil		% wage indexation degree
theta		% capital share production function
ksi         % firm fixed cost
alph		% Calvo prob not reset prices
chi         % price indexation degree
g_ss		% steady state government spending
pi_tar  % ss inflation inflation target in SW
R_tar   % ss interest rate target


% phi         % monetary policy parameter

 crpi        % Taylor rule inflation feedback
 cry        % Taylor rule output feedback
 crdy         % Taylor rule output growth feedback
 crr         % interest rate persistence


    crhoz       ${\rho_a}$          (long_name='persistence productivity shock')
    cmaz        % MA parameter in the productivity process
    crhob       ${\rho_b}$          (long_name='persistence risk premium shock')
    crhog       ${\rho_g}$          (long_name='persistence spending shock')
    cgy         % parameter relating output with spending process
    crhoqs      ${\rho_i}$          (long_name='persistence risk premium shock')
    crhoms      ${\rho_r}$          (long_name='persistence monetary policy shock')
    crhopinf    ${\rho_p}$          (long_name='persistence price markup shock')
    cmap        % MA parameter in the price markup process
    crhow       ${\rho_w}$          (long_name='persistence wage markup shock')
    cmaw        % MA parameter in the wage markup process

;


% PARAMETER CALIBRATION

// fixed parameters                 %                %


% 1) PREFERENCES
b = 0.63;           % degree of habit persistence
beta = 1.03^(-1/4);	% subjective discount factor
phi0 = 1.1196 ;		% preference parameter labor


% 2) ELASTICITIES OF SUBSTITUTION
eta = 6;            % price-elasticity of demand for a differianted good
etatil = 21;		% elasticity substitution labor types


% 3) TECHNOLOGY
delt = 0.025;		% depreciation rate
theta = 0.36;		% share of capital
kap = 2.48;         % investment adj cost function
gam1 = 0.032417;	% cap utilization function
gam2 = 0.000324;	% cap utilization function
ksi = 0.5827;		% firm fixed cost



%    MODEL
model;
% capital accumulation AR Eq (15)
k = (1-delt)*k(-1) + invest - invest*(kap/2)*(((invest/invest(-1))-1)^2);

% HOUSEHOLD FIRST ORDER CONDITIONS
% household consumption Euler AR Eq (16)
(1/(c-b*c(-1))) - b*beta*(1/(c(+1)-b*c)) + gs = lamb;

% household labor decision AR Eq (17)

phi0*h = lamb*w/mutil;

% household capital decision AR Eq (18)
lamb*q = beta*lamb(+1)*((1-delt)*q(+1) + rk(+1)*u(+1) - gam1*(u(+1)-1) - (gam2/2)*((u(+1)-1)^2)) + bs;

% household investment decision AR Eq (19)
lamb = qs + lamb*q*(1 - (kap/2)*(((invest/invest(-1))-1)^2) - kap*(invest/invest(-1))*((invest/invest(-1))-1)) + beta*lamb(+1)*q(+1)*kap*((invest(+1)/invest)^2)*((invest(+1)/invest)-1);

% household capital utilization decision AR Eq (20)
gam1 + gam2*(u-1) = rk;

% household borrowing/lending Euler SGU Eq (20)
lamb = beta*R*(lamb(+1)/pi(+1));

% WAGE SETTING SGU Eqs (17)-(19)
f1 = ((etatil-1)/etatil)*wtil*lamb*((w/wtil)^etatil)*hd + alphtil*beta*((pi(+1)/(pi^chitil))^(etatil-1))*((wtil(+1)/wtil)^(etatil-1))*f1(+1);
f2 = phi0*h*((w/wtil)^etatil)*hd + alphtil*beta*((pi(+1)/(pi^chitil))^(etatil))*((wtil(+1)/wtil)^(etatil))*f2(+1);
f1 = f2;

% aggregate demand AR Eq (24)
y = c + invest + g + (gam1*(u-1) + (gam2/2)*((u-1)^2))*k(-1);

% FIRMS' DECISIONS
% firms' demand for capital services AR Eq (26)
mc*z*theta*((u*k(-1))^(theta-1))*(hd^(1-theta)) = rk;

% firms' demand for labor AR Eq (27)
mc*z*(1-theta)*((u*k(-1))^theta)*(hd^(-theta)) = w;

% PRICE SETTING SGU Eqs (29)-(31)
x1 = y*mc*(ptil^(-1-eta)) + alph*beta*(lamb(+1)/lamb)*((ptil(+1)/ptil)^(1+eta))*((pi(+1)/(pi^chi))^eta)*x1(+1);
x2 = y*(ptil^(-eta)) + alph*beta*(lamb(+1)/lamb)*((ptil(+1)/ptil)^eta)*((pi(+1)/(pi^chi))^(eta-1))*x2(+1);
eta*x1 = (eta-1)*x2;

% government constraint AR Eq (29)
g = tau;

% aggregate price SGU Eq (38)
1 = alph*(pi^(eta-1))*((pi(-1)^chi)^(1-eta)) + (1-alph)*(ptil^(1-eta)) + spinf;

% aggregate wage SGU Eq (47)
(w^(1-etatil)) = (1-alphtil)*(wtil^(1-etatil)) + alphtil*(w(-1)^(1-etatil))*(((pi(-1)^chitil)/pi)^(1-etatil)) +sw;

% dividends SGU Eq (48)
div = y - rk*u*k(-1) - w*hd;

% EQUILIBRIUM
% labor market SGU Rq (45)
h = stil*hd;

% Resource constraint SGU Eq (40)
z*((u*k(-1))^theta)*(hd^(1-theta)) - ksi = y*s;

% PRICE AND WAGE DISPERSION
% Price dispersion dynamics SGU Eq (41)
s = (1-alph)*(ptil^(-eta)) + alph*((pi/(pi(-1)^chi))^eta)*s(-1);

% Wage dispersion dynamics SGU Eq (46)
stil = (1-alphtil)*((w/wtil)^etatil) + alphtil*((w/w(-1))^etatil)*((pi/(pi(-1)^chitil))^etatil)*stil(-1);

% MONETARY POLICY
%(R/R_tar) = (pi/pi_tar)^phi;

% MONETARY POLICY
R/R_tar =  ((1-crr)*((pi/pi_tar)^(crpi)))
      +(1-crr)*(y-2.9135)*cry
      +(1-crr)*(y-y(-1))*crdy
      +crr*R(-1)/R_tar + ms;

% government spending
g = g_ss;

% Productivity
z = 1+zs;

[name='Law of motion for productivity']
	      zs = crhoz*zs(-1)  + ez +cmaz*ez(-1);
          [name='Law of motion for risk premium']
	      bs = crhob*bs(-1) + eb;
          [name='Law of motion for spending process']
	      gs = crhog*(gs(-1)) + eg + cgy*ez;
	        [name='Law of motion for investment specific technology shock process']
        qs = crhoqs*qs(-1) + eqs;
          [name='Law of motion for monetary policy shock process']
	      ms = crhoms*ms(-1) + em;
          [name='Law of motion for price markup shock process']
	      spinf = crhopinf*spinf(-1) + epinf - cmap*epinf(-1);
          [name='Law of motion for wage markup shock process']
	      sw = crhow*sw(-1) + ew - cmaw*ew(-1) ;



% variables generated for the simulations
yd = 100*(y-2.9135)/2.9135;     % steady state output is 2.9135
pi_y = 100*((pi^4)-1);
pi_q = 100*(pi-1);
end;

steady_state_model;

% EXACT STEADY STATE VALUES
u = 1;          % capacity utilization
pi_tar = 1.007;	% ss inflation inflation target in  SW
pi = pi_tar;   	% gross inflation
q = 1;          % market value capital
rk = gam1;      % rental price capital
div = 0;        % dividends
R_tar = pi_tar/beta;	% nominal interest rate target in AR
R = R_tar;      % nominal gross interest rate
z = 1;

% 3) CALVO PARAMETERS
alphtil = 0.64;		% on wages
alph = 0.60;		% on prices


% 4) INDEXATION
chitil = 1;		% on wages
chi = 1;		% on prices

% 5) MONETARY POLICY
crpi = 1.5;   % monetary policy parameter pi
crr = 0.85;    % monetary policy parameter r
cry = 0.05;    % monetary policy parameter y
crdy = 0.2;    % monetary policy parameter dy


% 6) STEADY STATE
g_ss = 0.498777018;	% ss government spending (residual)



  % persistence shocks

crhoz=    0.9977;
cmaz= 0;

crhob=    0.5799;

crhog=    0.9957;
cgy=      0.51;

crhoqs=   0.7165;

crhoms=0;


crhopinf=0;
cmap = 0;

crhow=0;
cmaw  = 0;



ptil = ((1/(1-alph))*(1-alph*pi^(-(eta-1)*(1-chi))))^(1/(1-eta));	% relative price optimizing firm
s = ((1-alph)*ptil)/(1-alph*pi^(eta*(1-chi)));      % cross section price dispersion
mc = ((eta-1)/eta)*ptil*((1-alph*beta*pi^(eta*(1-chi)))/(1-alph*beta*pi^(-(1-eta)*(1-chi)))); % marginal cost
w = (1-theta)*(mc^(1/(1-theta)))*((theta/rk)^(theta/(1-theta)));   	% real wage
wtil = w*(((1/(1-alphtil))*(1 - alphtil*(pi^(-(1-chitil)*(1-etatil)))))^(1/(1-etatil))); % real wage optimizing firm
stil = ((1-alphtil)*((w/wtil)^etatil))/(1-alphtil*pi^(etatil*(1-chitil))); % cross section wage dispersion
y = (mc*ksi)/(1-mc*s);  % output
x1 = (y*mc*ptil^(-(1+eta)))/(1 - alph*beta*(pi^(eta*(1-chi))));
x2 = x1*(eta/(eta-1));
k = (theta*mc*(y*s + ksi))/(u*rk);  % capital stock
hd = ((1-theta)*mc*(y*s + ksi))/(w);    % worker hours demanded
h = stil*hd;    % hours worked
invest = delt*k;    % capital investment
f2 = (phi0*stil*(hd^2)*((w/wtil)^etatil))/(1-alphtil*beta*(pi^((1-chitil)*etatil)));    % term for recursive expression for wage
f1 = f2;    % term for recursive expression for wage
lamb = (f1*(1-alphtil*beta*(pi^((1-chitil)*(etatil-1)))))/(((etatil-1)/etatil)*wtil*hd*((w/wtil)^etatil)); % Lagrange multiplier household budget constraint
mutil = (lamb*w)/(phi0*h);  % (inverse of) Lagrange multiplier labor supply AR (14)
c = (1-b*beta)/(lamb*(1-b));    % consumption
g = g_ss;
tau = g;     % lump sum tax
yd = 100*(y-2.9135)/2.9135;
pi_y = 100*((pi^4)-1);
pi_q = 100*(pi-1);

    zs = 0;
    bs = 0;
    gs = 0;
    qs = 0;
    ms = 0;
    spinf = 0;
    sw = 0;

end;

//check the starting values for the steady state
resid;

// compute steady state given the starting values
steady;

// check Blanchard-Kahn-conditions
check;


varobs c invest y h pi w R;

estimated_params;
// PARAM NAME, INITVAL, LB, UB, PRIOR_SHAPE, PRIOR_P1, PRIOR_P2, PRIOR_P3, PRIOR_P4, JSCALE
// PRIOR_SHAPE: BETA_PDF, GAMMA_PDF, NORMAL_PDF, INV_GAMMA_PDF
stderr ez,0.4618,0.01,3,INV_GAMMA_PDF,0.1,2;
stderr eb,0.1818513,0.025,5,INV_GAMMA_PDF,0.1,2;
stderr eg,0.6090,0.01,3,INV_GAMMA_PDF,0.1,2;
stderr eqs,0.46017,0.01,3,INV_GAMMA_PDF,0.1,2;
stderr em,0.2397,0.01,3,INV_GAMMA_PDF,0.1,2;
stderr epinf,0.1455,0.01,3,INV_GAMMA_PDF,0.1,2;
stderr ew,0.2089,0.01,3,INV_GAMMA_PDF,0.1,2;
crhoz,.9676 ,.01,.9999,BETA_PDF,0.5,0.20;
crhob,.2703,.01,.9999,BETA_PDF,0.5,0.20;
crhog,.9930,.01,.9999,BETA_PDF,0.5,0.20;
cgy,0.05,0.01,2.0,NORMAL_PDF,0.5,0.25;
crhoqs,0.5724,.01,.9999,BETA_PDF,0.5,0.20;
crhoms,.3,0.01,.9999,BETA_PDF,0.5,0.20;
crhopinf,0.8692,0.01,0.9999,BETA_PDF,0.5,0.20;
crhow,0.9546,0.001,0.9999,BETA_PDF,0.5,0.20;
cmaz, 0.5, 0, 0.9999, BETA_PDF, 0.5,0.2;
cmap,0.7652,0.01,0.9999,BETA_PDF,0.5,0.2;

g_ss, 0.498777018, 0, 1, NORMAL_PDF, 0.5, 0.15;

alphtil,0.64,0.3,0.95,BETA_PDF,0.64,0.1;
alph,0.6,0.3,0.95,BETA_PDF,0.6,0.10;
chitil,0.9,0.15,1.00,BETA_PDF,0.9,0.01;
chi,0.9,0.15,1.00,BETA_PDF,0.9,0.01;

crpi,1.7985,1.0,3,NORMAL_PDF,1.5,0.25;
crr,0.8258,0.5,0.975,BETA_PDF,0.75,0.10;
cry,0.05,0.001,0.5,NORMAL_PDF,0.05,0.05;
crdy,0.2239,0.001,0.5,NORMAL_PDF,0.2,0.05;
pi_tar,1.007,1.001,1.01,GAMMA_PDF,1.00625,0.002;

end;


estimated_params_init(use_calibration);
end;


estimation (optim=('MaxIter',200),datafile=AR_data_lineardetrendc,mode_compute=6,first_obs=1,mh_nblocks=2,mh_jscale=0.20,mh_drop=0.2, nograph, nodiagnostic, tex) w sw pi_y h y zs;

write_latex_prior_table;

And this is the CSV datafile.
AR_data_lineardetrendc.csv (10.8 KB)

Obs: The original data I used came from Smets and Wouters’s Excell file, found in its replication package. However, while SW uses growth rates for output and its compounds, I use the detrended values of their per worker logs, subtracting a linear trend. .

The code and the datafile I sent are with the 7 varobs and shock processes used in Smets and Wouters. Aiming at avoiding singularity, later I have withdrawn consumption as varobs, and after this I have withdrawn also output, but the singularity remained.

This is strange. Maybe @rattoma can have a look. The singularity seems to no be due to perfect collinearity among the observables. Rather it appears after a few iterations, i.e. it is at least partially related to the data. That explains why dropping a single series does not solve the issue.

1 Like