How to load a previously Estimated Model Parameters

Hi there!

I’d like to know how can I load the parameters and results from a previously estimated model, in order to perform simulations and conditional forecasts. Everytime I run my files, I do estimate, and then stoch_simul and my conditional forecasts. But now, I’m not willing to fit the model against the data anymore, I’m just willing to retrieve my last estimated model, and use stock_simul and conditional forecasts over this last estimated model. Is there a simple way of doing that using dynare commands on my file?

Thanks in advance,

Fernando

After estimation, Dynare saves the results in the results file, where it writes the posterior mean to M_. You can easily load this. Make sure to rename your mod-file in order to not overwrite your estimation results. Then, inside of this mod-file use

x=load('mymodel_results.mat'); M_.params=x.M_.params; stoch_simul;

1 Like

Dear Johannes,

First of all, thank you so much for all your dedication and efforts on spreading DSGE and Dynare.

Another doubt, linked to the first question is, after running the commands you’ve told me, I still can’t do a conditional forecast.
I’ve added the following code to my .mod file:

z=load('sw_fa_brX_results_MH.mat');
M_.params=z.M_.params;
oo_=z.oo_;
estim_params_=z.estim_params_;

I have the following error, after trying to do a conditional forecast:

[quote]
Error using initialize_dataset (line 24)
Estimation:: You have to declare a dataset file!
Error in imcforecast (line 119)
dataset_ =
initialize_dataset(options_.datafile,options_.varobs,options_.first_obs,options_.nobs,transformation,options_.prefilter,xls);
Error in sw_fa_brX (line 713)
imcforecast(constrained_paths_, constrained_vars_, options_cond_fcst_);
Error in dynare (line 180)
evalin(‘base’,fname) ; [/quote]

Thus, it seems it is asking to initialize a data-set. On the other hand, usually, I do it automatically inside the “estimate” command.
So, how can I do it separately?

Thank you so much for your help!

Best Regards,

Fernando Fernandes Neto

Dear Johannes,

I’ve already figured out how to do that.

Thank you so much for your kindness.

Fernando

To those with the same doubt, after the commands Mr. Johannes posted, include:

estimation(datafile=your_filename, mh_replic=0, mh_blocks=1, mh_drop=0.2, mh_jscalr=0.2, mode_compute=0, plot_priors=0);

This command will load up your dataset, without estimating anything.

I hope it may be useful for anyone.

1 Like

Dear Dynare users

I want to load the posterior means of the estimated parameters in OSR procedure. To this end, I proceed as follows:

[quote=“jpfeifer”]After estimation, Dynare saves the results in the results file, where it writes the posterior mean to M_. You can easily load this. Make sure to rename your mod-file in order to not overwrite your estimation results. Then, inside of this mod-file use

x=load('mymodel_results.mat'); M_.params=x.M_.params; stoch_simul;[/quote]

where the command stoch_simul is now replaced by osr.

When estimating the model, my mod file is labelled as model1.mod, while in the osr procedure I rename it to model2.mod. The results matrix after the estimation is model1_results.mat. After the OSR procedure, I get the following error:

Undefined function ‘model1_set_auxiliary_variables’ for input arguments of type
’double’.

Error in evaluate_steady_state (line 51)
ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params);

Error in resol (line 104)
[dr.ys,M.params,info] = evaluate_steady_state(oo.steady_state,M,options,oo,0);

Error in osr_obj (line 48)
[dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);

Error in osr1 (line 71)
[loss,vx,info,exit_flag]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var));

Error in osr (line 40)
osr1(i_params,i_var,W);

Error in SimpleRule (line 966)
osr(var_list_,osr_params_,obj_var_,optim_weights_);

Error in dynare (line 180)
evalin(‘base’,fname) ;

Does anyone know what’s going wrong?

My guess is that instead of the correct

you used

load('mymodel_results.mat');

and thereby overwrote all variables in the workspace

Dear jpfeifer,

thank you very much for your quick reply. When loading the posterior mean of the estimated parameters, I used
x=load(‘model1_results.mat’);
M_.params=x.M_.params;
osr (nograph) pi_hat y_hat;

This is ok. As you wrote, the problem is when I’m loading the estimates of the volatility of shocks. Here I used:
load model1_results.mat;
myshocks=oo_.posterior_mean.shocks_std;
myshocksmat=cell2mat(struct2cell(myshocks));

shocks;
// Non-stationary technology growth
var epsilon_muz;
stderr myshocksmat(1);

// Stationary technology
var epsilon_epsilon;
stderr myshocksmat(2);

etc.

Is it possible to use:
xr=load model1_results.mat;
myshocks=xr.oo_.posterior_mean.shocks_std;
myshocksmat=cell2mat(struct2cell(myshocks));
?

Thank you in advance.

Yes, as long as you load your results into a structure, nothing can happen. Of course, the correct syntax would be