# How to load a previously Estimated Model Parameters

**URL:** https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345
**Category:** Dynare help (legacy posts)
**Created:** [11 December 2014 10:20 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345 "2014-12-11T10:20:22Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![fernando.fernandes](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/b3f665/32.png) [@fernando.fernandes](https://forum.dynare.org/u/fernando.fernandes)
#### Post date: [11 December 2014 10:20 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/1 "2014-12-11T10:20:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)
#### Post date: [11 December 2014 19:00 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/2 "2014-12-11T19:00:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fernando.fernandes](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/b3f665/32.png) [@fernando.fernandes](https://forum.dynare.org/u/fernando.fernandes)
#### Post date: [12 December 2014 01:52 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/3 "2014-12-12T01:52:28Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![fernando.fernandes](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/b3f665/32.png) [@fernando.fernandes](https://forum.dynare.org/u/fernando.fernandes)
#### Post date: [12 December 2014 10:11 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/4 "2014-12-12T10:11:24Z")

</div>

Dear Johannes,

I’ve already figured out how to do that.

Thank you so much for your kindness.

Fernando

---

<div class="post-metadata">

### Author: ![fernando.fernandes](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/b3f665/32.png) [@fernando.fernandes](https://forum.dynare.org/u/fernando.fernandes)
#### Post date: [12 December 2014 17:08 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/5 "2014-12-12T17:08:20Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![econ86](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@econ86](https://forum.dynare.org/u/econ86)
#### Post date: [18 August 2015 12:53 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/6 "2015-08-18T12:53:33Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)
#### Post date: [18 August 2015 12:55 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/7 "2015-08-18T12:55:24Z")

</div>

My guess is that instead of the correct

> [@](#):
>
> x=load(‘mymodel\_results.mat’);

you used

```auto
load('mymodel_results.mat');
```

and thereby overwrote all variables in the workspace

---

<div class="post-metadata">

### Author: ![econ86](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@econ86](https://forum.dynare.org/u/econ86)
#### Post date: [18 August 2015 13:14 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/8 "2015-08-18T13:14:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)
#### Post date: [18 August 2015 13:45 UTC](https://forum.dynare.org/t/how-to-load-a-previously-estimated-model-parameters/4345/9 "2015-08-18T13:45:09Z")

</div>

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

```auto

```
