# Bayesian Estimation and Steady State Updating

**URL:** <https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787>\
**Category:** ML/Bayesian estimation\
**Created:** [22 October 2012 18:34 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787 "2012-10-22T18:34:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niklas](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@Niklas](https://forum.dynare.org/u/Niklas)\
**Post date:** [22 October 2012 18:34 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/1 "2012-10-22T18:34:29Z")

</div>

Hello,

I have a general question concerning bayesian estimation:

Suppose I would like to estimate the parameters of a DSGE model and in particular the disount factor betta. Since I loglinearize my model, the steady state interest rate Rss shows up in the model part as parameter. I know that in the steady state Rss=1.0/betta, which is written down in the parameters block. During the MCMC run, Dynare draws many different values for betta. My question now is whether Rss is updated each draw as well or whether it is held constant all the time (and equal its initial steady state value).

In case it is not updated, could I fix this problem only by using an external steady state file?

In case it is updated, is it nevertheless a good idea to use an external steady state file because it is always faster? (I.e. is it faster to use an external steady state file although I have solved for the whole steady state analytically in the parameters block?)

I am thankful for any help,  
best wishes,  
Niklas

---

<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:** [22 October 2012 20:45 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/2 "2012-10-22T20:45:31Z")

</div>

No, parameters defined before the model-block are not updated during estimation. Hence, you should either use a steady state file or use the pound operator. If your model is loglinearized, the overhead of the steady state file is not ideal. Hence, I would recommend using Expressions.

You could for example add to the model-block

```auto

```

and use Rss in the model as before. When estimating betta, Dynare will update this expression for Rss in dependence on betta. I hope this helps.

---

<div class="post-metadata">

**Author:** ![Niklas](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@Niklas](https://forum.dynare.org/u/Niklas)\
**Post date:** [23 October 2012 09:10 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/3 "2012-10-23T09:10:00Z")

</div>

Dear jpfeifer,

as always thank you very much! This helps!

One question concerning the speed of computation (What do you mean exactly by “overhead of the steady state file” in this context?):  
If I have a large DSGE model, NOT log-linearized, where the steady state is currently calculated in the parameters block, what is faster when it comes to estimation: Computing the steady state using the pound operator (although this could get very messy) or using an external steady state file?

All the best,  
Niklas

---

<div class="post-metadata">

**Author:** ![sebastien](https://forum.dynare.org/user_avatar/forum.dynare.org/sebastien/32/19973_2.png) [@sebastien](https://forum.dynare.org/u/sebastien)\
**Post date:** [12 November 2012 14:59 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/4 "2012-11-12T14:59:08Z")

</div>

An external steady state file is clearly the fastest implementation.

---

<div class="post-metadata">

**Author:** ![Lara](https://forum.dynare.org/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Lara](https://forum.dynare.org/u/Lara)\
**Post date:** [8 February 2013 09:11 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/5 "2013-02-08T09:11:07Z")

</div>

Dear jpfeifer and Niklas,

I did not manage to update the steady-state when I estimate the model.  
I added after “model(linear)” the definition of  
#Rss=1/betta;  
But I get an error message: **Rss has wrong type, you cannot use it within as left-hand side of a pound (’#’) expression**

In the code I first declared R\_ss as a parameter, then I have inserted its definition with the pound operator in front of it (after “model(linear)”). I am using dynare version 4.2.4. How can I update the steady state correctly?

You help (also an example with a mod file) would be greatly appreciated.  
Best regards,  
Lara

---

<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:** [8 February 2013 14:27 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/6 "2013-02-08T14:27:45Z")

</div>

You cannot define Rss as a parameter and an expression. Delete it as a parameter. You only need betta as a parameter.

---

<div class="post-metadata">

**Author:** ![mbbr](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@mbbr](https://forum.dynare.org/u/mbbr)\
**Post date:** [25 February 2013 12:05 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/7 "2013-02-25T12:05:37Z")

</div>

Similar to Lara,

I defined first rss kss, iss as paramater in the parameter block and I deleted them from parameter block and deleted from parameter names and wrote in model block. But I still got the same answer with Lara.

k\_over\_ghss has wrong type, you cannot use it within as left-hand side of a pound (’#’) expression.

Could you help me?

---

<div class="post-metadata">

**Author:** ![gin](https://forum.dynare.org/user_avatar/forum.dynare.org/gin/32/19654_2.png) [@gin](https://forum.dynare.org/u/gin)\
**Post date:** [27 March 2013 09:28 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/8 "2013-03-27T09:28:43Z")

</div>

[quote=“Niklas”]Dear jpfeifer,

as always thank you very much! This helps!

One question concerning the speed of computation (What do you mean exactly by “overhead of the steady state file” in this context?):  
If I have a large DSGE model, NOT log-linearized, where the steady state is currently calculated in the parameters block, what is faster when it comes to estimation: Computing the steady state using the pound operator (although this could get very messy) or using an external steady state file?

All the best,  
Niklas[/quote]

As far as I understand, if the model is not linearized then using the pound operator and subsequently setting up the _initval;_ block is a mess because one has to express the ss-values in the _initval;_ block as functions of parameters (if one wants to use ss-values in the _initval;_ block) and therefore one gets pretty long expressions. Thus, if model is not linearized, there is a clear advantage of using the ss-file.

---

<div class="post-metadata">

**Author:** ![gin](https://forum.dynare.org/user_avatar/forum.dynare.org/gin/32/19654_2.png) [@gin](https://forum.dynare.org/u/gin)\
**Post date:** [27 March 2013 12:26 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/9 "2013-03-27T12:26:53Z")

</div>

Regarding the speed, here is an example:

Schmitt-Grohe&Uribe (2003) non-linearized model with 12 vars; 9 estimated params using one observed variable; details here:

```auto
estimation(order=1, datafile=grohe_uribe03data, mh_replic=2000, mh_nblocks=2, mh_jscale=0.02, mode_compute=6, forecast=40) y_obs;  
```

The ss-file takes **10min** , while the pound-operator shouts about ‘SOLVE: maxit has been reached’ and takes **32min**.

The posteriors and thus estimated ss-vals are not identical either: while the ss-file stays close to the (rather tightly specified) priors, the pound operator has changed some of the distributions.

The files attached; the data here:

[code]y\_obs =

```
0.0093
0.0098
0.0059
0.0077
0.0062
0.0215
0.0199
0.0230
0.0347
0.0130
0.0339
0.0053
0.0187
0.0076

```

-0.0311  
0.0306  
-0.0067  
0.0273  
0.0067  
0.0129  
0.0092  
0.0309  
0.0024  
0.0236  
0.0342  
-0.0091  
0.0303  
0.0073  
0.0267  
0.0239  
0.0226  
0.0161  
0.0133  
0.0216  
0.0134  
0.0289  
0.0229  
0.0055  
0.0186  
0.0278  
0.0244  
0.0423  
0.0313  
0.0203  
0.0262  
0.0188  
0.0311  
0.0293  
0.0282  
0.0024  
0.0134  
-0.0105  
-0.0056  
-0.0605  
-0.0200  
-0.1061  
-0.0110  
-0.0682  
0.0102  
0.0068  
0.0041  
0.0066  
0.0108  
0.0149  
0.0198  
0.0128  
0.0095  
0.0126  
0.0138  
0.0165  
0.0135[/code]  
[grohe\_uribe03est\_pound.mod](https://forum.dynare.org/uploads/default/original/2X/d/d5d766594b552f4b97b2de23942242ee7462f394.mod) (4.13 KB)  
[grohe\_uribe03est\_steadystate.m](https://forum.dynare.org/uploads/default/original/2X/e/e9a415fc6b3caeb248ac1ef04eb4094da39d50f0.m) (2.52 KB)  
[grohe\_uribe03est.mod](https://forum.dynare.org/uploads/default/original/2X/5/5a308e30c8e9e1dbe3364ad548b1007e10abf9a8.mod) (3.09 KB)

---

<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:** [27 March 2013 13:10 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/10 "2013-03-27T13:10:03Z")

</div>

Note that the initval-block is executed sequentially. Thus, you could use

`inv=deltaa*k;
`  
if k has been solved before. This simplifies the mess a bit.

Moreover, your initial values only work for the baseline calibration. If you set alpha=0.9 the residuals are not 0. Thus, Dynare always numerically solves the SS, which explains the slowness.

---

<div class="post-metadata">

**Author:** ![gin](https://forum.dynare.org/user_avatar/forum.dynare.org/gin/32/19654_2.png) [@gin](https://forum.dynare.org/u/gin)\
**Post date:** [27 March 2013 14:58 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/11 "2013-03-27T14:58:13Z")

</div>

Indeed, not that messy for this model:

```auto
var d c h y inv k a lambdaa tb ca riskpremium r 
       y_obs;  

varexo e;                                    
                                             
parameters gammaa, omegaa, rhoo, sigmae, deltaa, psii, alphaa, phii, r_w, d_bar;

		alphaa = 0.32;
		rhoo = 0.42;
		phii = 0.028;
		r_w = 0.04;		
 gammaa = 2;
		omegaa = 1.455;
		psii = 0.000742;
		deltaa = 0.1;
		sigmae = 0.0129;
		d_bar = 0.7442;

		

model;
    #betaa = 1/(1+r_w);
    #h_ss = ((1-alphaa)*(alphaa/(r_w+deltaa))^(alphaa/(1-alphaa)))^(1/(omegaa-1)); 
	#k_ss = h_ss/(((r_w+deltaa)/alphaa)^(1/(1-alphaa)));
	#inv_ss = deltaa*k_ss;                                                     
	#y_ss = (k_ss^alphaa)*(h_ss^(1-alphaa));                                   
	#d_ss = d_bar;                                                        
	#c_ss = y_ss-inv_ss-r_w*d_ss;
	#tb_ss = y_ss-c_ss-inv_ss;
    d = (1+exp(r(-1)))*d(-1)- exp(y)+exp(c)+exp(inv)+(phii/2)*(exp(k)-exp(k(-1)))^2;
    exp(y) = exp(a)*(exp(k(-1))^alphaa)*(exp(h)^(1-alphaa));
    exp(k) = exp(inv)+(1-deltaa)*exp(k(-1)); 
    exp(lambdaa)= betaa*(1+exp(r))*exp(lambdaa(+1)); 
    (exp(c)-((exp(h)^omegaa)/omegaa))^(-gammaa) = exp(lambdaa);  
    ((exp(c)-((exp(h)^omegaa)/omegaa))^(-gammaa))*(exp(h)^omegaa) = exp(lambdaa)*(1-alphaa)*exp(y); 
    exp(lambdaa)*(1+phii*(exp(k)-exp(k(-1)))) = betaa*exp(lambdaa(+1))*(alphaa*exp(y(+1))/exp(k)+1-deltaa+phii*(exp(inv(+1))-deltaa*exp(k))); 
    a = rhoo*a(-1)+e; 
    tb = 1-((exp(c)+exp(inv))/exp(y));
    ca = (1/exp(y))*(d-d(-1));                                   
    riskpremium = psii*(exp(d-d_bar)-1);
    exp(r) = r_w+riskpremium;

    y_obs = 0.012+ y-y(-1); //yoy ss growth 4.8%
end;

// dynare solves ss numerically at every iter which explains the slowness
initval;
    r = log((1-1/(1+r_w))/(1/(1+r_w)));
    d = d_bar;
    h = log(((1-alphaa)*(alphaa/(r_w+deltaa))^(alphaa/(1-alphaa)))^(1/(omegaa-1)));
    k = log(exp(h)/(((r_w+deltaa)/alphaa)^(1/(1-alphaa))));
    inv=log(deltaa)+k;
    y=alphaa*k+(1-alphaa)*h;
    c=log(exp(y)-exp(inv)-r_w*d);
    tb = 1-((exp(c)+exp(inv))/exp(y));
    lambdaa= log((exp(c)-((exp(h)^omegaa)/omegaa))^(-gammaa));
    y_obs=0.012; //yoy ss growth 4.8%
end;

shocks;
    var e; stderr sigmae;
end;

resid(1);

steady; 

check;

estimated_params;
alphaa, beta_pdf, 0.3, .005;
rhoo, beta_pdf, 0.42, .002;
phii, beta_pdf, 0.028, .001;
r_w, beta_pdf, 0.02, .005;		
gammaa, normal_pdf, 2, .01;
omegaa, normal_pdf, 1.455, .01;
psii, beta_pdf, 0.000742, .0000001;
deltaa, beta_pdf, 0.1, .001;
d_bar, beta_pdf, 0.7442, .001;

//stderr sigmae, inv_gamma_pdf, 0.0129, inf;
end;

varobs y_obs;

estimation(order=1, datafile=grohe_uribe03data, mh_replic=2000, mh_nblocks=2, mh_jscale=0.4, 
 mode_compute=6, forecast=40) y_obs;
```

---

<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:** [14 December 2018 12:02 UTC](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/13 "2018-12-14T12:02:30Z")

</div>

You need to be more precise. What is the particular setup you have in mind?
