Using the forecast command to estimate one parameter while varying others

Hi,
I am estimating one parameter of a very simple DSGE model for different values of some of the other parameters by matching an observed forecast of a professional forecaster with the forecast of the model. The criterion function is the squared difference between the model forecast and the forecast of the professional forecaster, and look for a way to speed up the estimation routine. I am using fminsearch to minimize the criterion, and fminsearch executes dynare to solve the model at each iteration, so each time dynare has to parse the model file which slows down the computation. Is there a way around this? For instance, would it be possible to somehow call fminsearch within the .mod file, and the execute only stoch_simul and forecast? I found a similar problem in this forum using only stoch_simul, but not the forecast command. Based on the errors message I received, it seems I don’t know how to use the forecast command. Is it possible to call the dynare projection command outside the .mod in the same way as the stoch_simul command?

Many thanks for your help!
Best,
Waldyr

Yes, that should be straightforward to do. If you can provide the current files, I may be able to assist.

Thank you for your reply. Please find the files attached. The error I receive is

Not enough input arguments.

Error in forecast (line 29)
nvar = nn(1);

Error in Forecast_matching_objective (line 51)
forecast;

I am sending a reduced database with fictitious data but with the same fields as the original database.

solveModel_ComFunc.mod (5.6 KB)
Forecast_matching_objective.m (2.5 KB)
focusForecasts.m (1.3 KB)
Série de estatísticas.xlsx (13.9 KB)

The second sheet in the Excel file is missing. But the relevant loop part should be over:

[oo_.dr, info, M_.params] = resol(0, M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state)

oo_.forecast = dyn_forecast(var_list_,M_,options_,oo_,'simul');

Thank you very much for your answer. I’m receiving the following error message:

Unrecognized function or variable ‘check_flag’.

Error in Forecast_matching_objective (line 39)
[oo_.dr, info, M_.params] = resol(check_flag, M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state)

I included the lines of code you suggested inside the following .m function. Did I misunderstand where to include the code?

Thank you again for your help!

Forecast_matching_objective.m (2.6 KB)

Sorry, my mistake. It should be

[oo_.dr, info, M_.params] = resol(0, M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state)

I fixed the above post.

Thank you again for your help. Now I received the following message:

Error using resol
Too many input arguments.

Error in Forecast_matching_objective (line 39)
[oo_.dr, info, M_.params] = resol(0, M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);

I’m using dynare 5.3…I took a look:

help resol
Computes the perturbation based decision rules of the DSGE model (orders 1 to 3)

INPUTS

  • check_flag [integer] scalar, equal to 0 if all the approximation is required, equal to 1 if only the eigenvalues are to be computed.
  • M [structure] Matlab’s structure describing the model (M_).
  • options [structure] Matlab’s structure describing the current options (options_).
  • oo [structure] Matlab’s structure containing the results (oo_).

OUTPUTS

  • dr [structure] Reduced form model.
  • info [integer] scalar or vector, error code.
  • M [structure] Matlab’s structure describing the model (M_).
  • oo [structure] Matlab’s structure containing the results (oo_).

I tried [oo_.dr, info, M_.params, oo_] = resol(0, M_, options_, oo_);

But received the following:

Unable to perform assignment because the left and right sides have a different number of elements.

Error in dyn_first_order_solver (line 226)
info(2) = temp’*temp;

Error in stochastic_solvers (line 251)
[dr,info] = dyn_first_order_solver(jacobia_,M_,dr,options_,task);

Error in resol (line 119)
[dr,info] = stochastic_solvers(dr,check_flag,M,options,oo);

Error in Forecast_matching_objective (line 39)
[oo_.dr, info, M_.params, oo_] = resol(0, M_, options_, oo_);

Please upgrade to Dynare 6.1. You may also need to add

if isempty(options_.qz_criterium)
    options_.qz_criterium = 1+1e-6;
end

Thank you again for your help. I’ll upgrade to Dynare 6.1.