How to load a previously Estimated Model Parameters

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

How to load a previously Estimated Model Parameters

Postby fernando.fernandes » Thu Dec 11, 2014 10:20 am

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
fernando.fernandes
 
Posts: 8
Joined: Mon Nov 17, 2014 5:09 pm

Re: How to load a previously Estimated Model Parameters

Postby jpfeifer » Thu Dec 11, 2014 7:00 pm

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

Code: Select all
x=load('mymodel_results.mat');
M_.params=x.M_.params;
stoch_simul;
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: How to load a previously Estimated Model Parameters

Postby fernando.fernandes » Fri Dec 12, 2014 1:52 am

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:

Code: Select all
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:

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) ;


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
fernando.fernandes
 
Posts: 8
Joined: Mon Nov 17, 2014 5:09 pm

Re: How to load a previously Estimated Model Parameters

Postby fernando.fernandes » Fri Dec 12, 2014 10:11 am

Dear Johannes,

I've already figured out how to do that.

Thank you so much for your kindness.

Fernando
fernando.fernandes
 
Posts: 8
Joined: Mon Nov 17, 2014 5:09 pm

Re: How to load a previously Estimated Model Parameters

Postby fernando.fernandes » Fri Dec 12, 2014 5:08 pm

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

Code: Select all
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.
fernando.fernandes
 
Posts: 8
Joined: Mon Nov 17, 2014 5:09 pm

Re: How to load a previously Estimated Model Parameters

Postby econ86 » Tue Aug 18, 2015 12:53 pm

Dear Dynare users

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

jpfeifer wrote: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

Code: Select all
x=load('mymodel_results.mat');
M_.params=x.M_.params;
stoch_simul;


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?
econ86
 
Posts: 78
Joined: Sun Apr 26, 2015 10:32 am

Re: How to load a previously Estimated Model Parameters

Postby jpfeifer » Tue Aug 18, 2015 12:55 pm

My guess is that instead of the correct
x=load('mymodel_results.mat');

you used
Code: Select all
load('mymodel_results.mat');

and thereby overwrote all variables in the workspace
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: How to load a previously Estimated Model Parameters

Postby econ86 » Tue Aug 18, 2015 1:14 pm

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.
econ86
 
Posts: 78
Joined: Sun Apr 26, 2015 10:32 am

Re: How to load a previously Estimated Model Parameters

Postby jpfeifer » Tue Aug 18, 2015 1:45 pm

Yes, as long as you load your results into a structure, nothing can happen. Of course, the correct syntax would be
Code: Select all
xr=load('model1_results.mat');
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 7 guests