Import end value from external file

Hello,

I am working on a dynamic production network model with 43 industries, where I’m analyzing the effect of a permanent demand shock on a given industry and the transition path to the new steady state. This is a perfect foresight exercise because there is nothing stochastic in my model - hence I’m using the perfect foresight solver. I have a large number of variables due to the size of the network - 217, to be precise.

It’s easy to specify the initial values, because the model is in “exact hat” form (every variable is specified as its proportion relative to its initial steady state), so the initvals are all 1. I can solve for the new steady state (the end values) outside of dynare, but I don’t know how to import those values into dynare to specify the endvals - is there a way to do this?

I have another issue with this model. Dynare throws me the following error:

Index in position 2 is invalid. Array indices must be positive integers or logical values.

Error in dynprodnetmodel.driver (line 437)
set_param_value(‘Delta_1_1’,Delta(i,j));

Error in dynare (line 310)
evalin(‘base’,[fname ‘.driver’]);

Error in checkerdyn (line 94)
dynare dynprodnetmodel.mod

What could be causing this?

I attach two files. In the first one, checkerdyn.m, I construct a simple 2-sector dataset as an example to calibrate my model. The other one, dynprodnetmodel.mod, is the dynare model I’m using. I only included initial values, and not end values, for now.

checkerdyn.m (2.3 KB)
dynprodnetmodel.mod (2.9 KB)

  1. Your macro loop is incorrect. For example
    set_param_value('alpha_@{i}',alpha(i)); // Capital share

should be

    set_param_value('alpha_@{i}',alpha(@{i})); // Capital share
  1. If you have the correct initial and terminal conditions, the easiest way is to bypass the initval and endval blocks and simply set the first and last entries of oo_.endo_simul and oo_.exo_simul, which stores the initial and terminal conditions.
1 Like

Thank you, the macro loop was indeed incorrect, that’s sorted. How can I set the first and last entries of the oo_.endo_simul matrix “manually”? An additional question: the initvals are the variable values before the shock hits, or right after?

Okay, so as I understand I can add to the perfect_foresight_setup command a data file which contains the initial guess for the path of the variables, and the initial and terminal values. I did that, I’m attaching the updated codes and the .mat file with row vectors for all variables (I’m specifying 200 simulation periods, so these are 202 entries long). I’m getting the following error messages:

Warning: Some of the parameters have no value (delta) when using perfect_foresight_setup. If these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able to solve the model. Note that simul, perfect_foresight_setup, and perfect_foresight_solver do not automatically call the steady state file.

Error using +
Arrays have incompatible sizes for this operation.

Error in perfect_foresight_solver>create_scenario (line 463)
exo_simul = exoorigshare/shareorig + exobase(1-share/shareorig);

Error in perfect_foresight_solver>homotopy_loop (line 338)
[steady_success, endo_simul, exo_simul, steady_state, exo_steady_state] = create_scenario(M_,options_,oo_,new_share, shareorig, endoorig, exoorig, endobase, exobase, initperiods, lastperiods, recompute_final_steady_state, endo_simul, steady_state, exo_steady_state);

Error in perfect_foresight_solver (line 153)
[completed_share, endo_simul, exo_simul, steady_state, exo_steady_state, iteration, maxerror, solver_iter, per_block_status] = homotopy_loop(M_,options_,oo_,options_.simul.homotopy_max_completion_share, shareorig, endoorig, exoorig, endobase, exobase, initperiods, simperiods, lastperiods, recompute_final_steady_state, oo_.steady_state, oo_.exo_steady_state);

Error in dynprodnetmodel.driver (line 465)
[oo_, Simulated_time_series] = perfect_foresight_solver(M_, options_, oo_);

Error in dynare (line 310)
evalin(‘base’,[fname ‘.driver’]);

Do you know why this could be happening? Am I on the right track by using perfect_foresight_setup to load the initial and terminal values?

dynprodnetmodel.mod (2.7 KB)

checkerdyn.m (3.5 KB)

initvalues.mat (903 Bytes)

Yes, you are on the right track. From what I can see, the problem is a Dynare bug. You can keep track at 🐛 make_ex_.m: correct matrix dimensions with datafile and exo_nbr==0 (!2292) · Merge requests · Dynare / dynare · GitLab

Perfect, thank you, I see the correction passed. Should I download the edited file and replace it in my dynare folders? Or how does this work?

Yes, you can download the corrected file.

Problem sorted, thank you again. I have another issue related to this code, but that’s unrelated, I’ll post it separately.