# How to do variance decomposition in dynare?

**URL:** <https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701>\
**Category:** Dynare help (legacy posts)\
**Created:** [5 September 2012 10:52 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701 "2012-09-05T10:52:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayong1982](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mayong1982](https://forum.dynare.org/u/mayong1982)\
**Post date:** [5 September 2012 10:52 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/1 "2012-09-05T10:52:03Z")

</div>

hello, every body. i have a question.

suppose the dynare code is as follows:

var xxxxx;  
varexo xxxxxxx ;  
parameters xxxxxx;  
model(linear);  
y = xxxxx  
……  
end;  
steady;  
check;

shocks;  
var ……  
end;

estimated\_params;  
xxxx, normal\_pdf, 0.03, 0.01;  
……  
stderr epsilon\_r, inv\_gamma\_pdf, 0.01, inf;  
….  
end;

varobs y pi;

stoch\_simul(irf=40, periods=600) y pi r;

estimation(datafile=data, prefilter=1, first\_obs=1, mh\_drop=0.45, mode\_compute=4, mode\_check, mh\_replic=20000);

my question is , how to add a command to let the dynare do variance decomposition? i mean both the command and where to put it.

---

<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:** [5 September 2012 14:44 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/2 "2012-09-05T14:44:47Z")

</div>

See the manual on conditional\_variance\_decomposition.

---

<div class="post-metadata">

**Author:** ![mayong1982](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mayong1982](https://forum.dynare.org/u/mayong1982)\
**Post date:** [6 September 2012 14:04 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/3 "2012-09-06T14:04:44Z")

</div>

> [@jpfeifer](#):
>
> See the manual on conditional\_variance\_decomposition.

thanks for ur help.

i have added the “conditional\_variance\_decomposition” command this:

stoch\_simul(irf=40, periods=600, conditional\_variance\_decomposition=40) y pi r;

but there are still no results…why?

---

<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:** [6 September 2012 15:06 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/4 "2012-09-06T15:06:57Z")

</div>

Please post the mod-file

---

<div class="post-metadata">

**Author:** ![mayong1982](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mayong1982](https://forum.dynare.org/u/mayong1982)\
**Post date:** [7 September 2012 04:57 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/5 "2012-09-07T04:57:49Z")

</div>

here is my mod file. thanks!  
[bbb.mod](https://forum.dynare.org/uploads/default/original/2X/b/b3452a5cc2d9ed00aafdcb53959c525df812451f.mod) (2.22 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:** [7 September 2012 06:40 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/6 "2012-09-07T06:40:42Z")

</div>

It only works with theoretical moments and only at first order as variance decomposition for nonlinear systems are state-dependent. Hence, set order=1 and periods=0.

---

<div class="post-metadata">

**Author:** ![mayong1982](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mayong1982](https://forum.dynare.org/u/mayong1982)\
**Post date:** [7 September 2012 17:27 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/7 "2012-09-07T17:27:01Z")

</div>

> [@jpfeifer](#):
>
> It only works with theoretical moments and only at first order as variance decomposition for nonlinear systems are state-dependent. Hence, set order=1 and periods=0.

when i do as u say, the dynare did give a variance decomposition report. but the trouble is that there is only one report. you know, in many papers, the variance decomposition report usually includes several different horizons, such as 1 quarter, 4 quarters, 8 quarters, 16 quarters, 32 quarters, etc. how can i do this in my dynare code? thanks.

---

<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:** [7 September 2012 18:37 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/8 "2012-09-07T18:37:32Z")

</div>

```auto

```

---

<div class="post-metadata">

**Author:** ![mayong1982](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mayong1982](https://forum.dynare.org/u/mayong1982)\
**Post date:** [8 September 2012 03:16 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/9 "2012-09-08T03:16:23Z")

</div>

> [@jpfeifer](#):
>
> `conditional_variance_decomposition=[1,4,8,16,32]`

it works. thank u so much.

---

<div class="post-metadata">

**Author:** ![Victor](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@Victor](https://forum.dynare.org/u/Victor)\
**Post date:** [3 February 2014 19:42 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/10 "2014-02-03T19:42:00Z")

</div>

Thanks a lot for this too.

---

<div class="post-metadata">

**Author:** ![settler03](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@settler03](https://forum.dynare.org/u/settler03)\
**Post date:** [22 May 2014 14:25 UTC](https://forum.dynare.org/t/how-to-do-variance-decomposition-in-dynare/2701/11 "2014-05-22T14:25:32Z")

</div>

Hello  
Just eliminate command “periods” in last line
