Forecasting in Julia

Hello to all,

I am using the excellent Dynare software in Julia and I would like to know how to produce forecast after a calib_smoother or an estimation has been made and how to access the calibration results (the smoothed variables). I am uploading my dataset and the code used for a simple 3-equation NK model.

data.csv (3.7 KB)

using CSV

var y pi i r g u;
varexo g_e u_e;

parameters beta sigma eta omega kappa phipi phiy rhog rhou; 

beta = 0.99;
sigma= 1;
eta  = 1;
omega= 0.8;
kappa= (sigma+eta)*(1-omega)*(1-beta*omega)/omega;

phipi= 1.5;
phiy = 0;
rhog = 0.5;
rhou = 0.5;

model(linear);
  y=y(+1)-(1/sigma)*(i-pi(+1))+g;
  g=rhog*g(-1)+g_e;
  u=rhou*u(-1)+u_e;
  pi=beta*pi(+1)+kappa*y+u;
  i=phiy*y+phipi*pi;
  r=i-pi(+1);
end;

shocks;
  var g_e; stderr 1;
  var u_e; stderr 1;
end;

steady;

check;

stoch_simul(order=1);


varobs y pi i;

calib_smoother(datafile='data.csv');

Thank you very much.

Dear @Santiago_D,
look at forecasting in the documentation (Forecasting · Dynare.jl) and in particular to the forecast_mode option.

When you use forecast_mode=smoother, you don’t need to run the smoother before hand.

Best
Michel

Thank you for your reply professor, looking at the forecasting documentation I am not sure how to specify the forecasting function; I changed my code to:

var y pi i r g u;
varexo g_e u_e;

parameters beta sigma eta omega kappa phipi phiy rhog rhou; 

beta = 0.99;
sigma= 1;
eta  = 1;
omega= 0.8;
kappa= (sigma+eta)*(1-omega)*(1-beta*omega)/omega;

phipi= 1.5;
phiy = 0;
rhog = 0.5;
rhou = 0.5;

model(linear);
  y=y(+1)-(1/sigma)*(i-pi(+1))+g;
  g=rhog*g(-1)+g_e;
  u=rhou*u(-1)+u_e;
  pi=beta*pi(+1)+kappa*y+u;
  i=phiy*y+phipi*pi;
  r=i-pi(+1);
end;

shocks;
  var g_e; stderr 1;
  var u_e; stderr 1;
end;

steady;

check;

stoch_simul(order=1);

forecasting!(periods=10,forecast_mode="smoother");

But I get this error: ErrorException(“Unrecognized statement native forecasting!(periods=10,forecast_mode="smoother");”)
2024-04-03T12:06:11.752: End parser

In fact the documentation isn’t sufficiently detailed:

  • in the forecast!() function, smoother doesn’t take double quotes
  • you need to indicate the datafile used for computing the smoother
  • you need to specify which are the observed variables
  • as there is two exogenous shocks you can’t have more than two observed variable. Otherwise, the model suffers from stochastic singularity

The following code works for me

var y pi i r g u;
varexo g_e u_e;

parameters beta sigma eta omega kappa phipi phiy rhog rhou; 

beta = 0.99;
sigma= 1;
eta  = 1;
omega= 0.8;
kappa= (sigma+eta)*(1-omega)*(1-beta*omega)/omega;

phipi= 1.5;
phiy = 0;
rhog = 0.5;
rhou = 0.5;

model(linear);
  y=y(+1)-(1/sigma)*(i-pi(+1))+g;
  g=rhog*g(-1)+g_e;
  u=rhou*u(-1)+u_e;
  pi=beta*pi(+1)+kappa*y+u;
  i=phiy*y+phipi*pi;
  r=i-pi(+1);
end;

shocks;
  var g_e; stderr 1;
  var u_e; stderr 1;
end;

steady;

check;

stoch_simul(order=1);

varobs y pi;

forecasting!(periods=10, datafile="data.csv", forecast_mode=calibsmoother);

Thank you very much for your reply, it works perfectly.