# Calculating variable variance

**URL:** <https://forum.dynare.org/t/calculating-variable-variance/28269>\
**Category:** Stochastic simulations\
**Created:** [13 February 2026 01:06 UTC](https://forum.dynare.org/t/calculating-variable-variance/28269 "2026-02-13T01:06:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonyxia324](https://forum.dynare.org/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@tonyxia324](https://forum.dynare.org/u/tonyxia324)\
**Post date:** [13 February 2026 01:06 UTC](https://forum.dynare.org/t/calculating-variable-variance/28269/1 "2026-02-13T01:06:39Z")

</div>

Hi everybody,

I have a conceptual issue regarding calculating the variance of endogenous variables. I understand that I can retrieve the variance-covariance information from oo\_.var after running the stochastic simulation. Suppose I define a variance explicitly in the mod file, and run a second-order simulation. What I discovered is that the mean of the explicitly defined variance is different compared to the one calculated in oo\_.var.

As a demonstration, I modified the example1 file provided in dyanre by adding an explicitly defined variance on consumption (varc). After running a second-order simulation, the variance of consumption shown in oo\_.var is 0.0028, while the explicitly defined variance varc shows a mean close to 0. I am confused about what causes the difference between the two. Thanks, everybody, for the attention.

Best regards,

Tian Xia

[example1.mod](https://forum.dynare.org/uploads/short-url/qFU8IukIAA7guFQYgR3H0W6PFih.mod) (1.6 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:** [19 February 2026 13:19 UTC](https://forum.dynare.org/t/calculating-variable-variance/28269/2 "2026-02-19T13:19:54Z")

</div>

There is a difference whether you compute a nonlinear function (variance) based on an approximation of the model and whether you approximate the nonlinear function within the model. The function

```auto
varc=(c(+1)-ec)^2;

```

will be approximated at the deterministic steady state, where its derivative is 0. It’s the same reason why you cannot solve portfolio choice models using perturbation.
