# Expected value of a power

Hello,

I’m new to Dynare and, hopefully, I have a very simple question. I was wondering which was the correct way of writing the following line into dynare:

E_t[x_{t+1}^y]

If I write it like “x(t+1)^y”, I’m afraid that Dynare would understand [E_t(x_{t+1})]^y, that is not what I want…

I thought of creating a new variable “z=x^y” and then simply write “z(+1)”, would that be correct?

Thanks a lot!

Fabrizio

No, if you write `x(t+1)^y`, then Dynare understands
E_t[x_{t+1}^y].

Dynare automatically prepends an E_t in front of all equations.

So you don’t need an auxiliary variable.

Best,

Actually, I think that Sébastien’s answer is not the whole story. There are cases (like the Epstein-Zin preferences you are trying to use, I guess) where you need an auxiliary variable, see [How to enter Jensen’s term correctly). From my experience, using this type of auxiliary variable works in Dynare.

The auxiliary variable is not needed except if you want to have the expectation of x_{t+1}^y inside a non linear function. For instance if in your model
you have something like

u(E_t[x_{t+1}^y]) = 0;

where u is a non linear function, then you just need to defin the auxiliary variable z as you propose and to rewrite the equation as

u(z(1)) = 0;

Best,
Stéphane.

I am actually working with Epstein-Zin preferences and so far using the auxiliary variable seems to work.

Best,

Fabrizio

Just to clarify Stéphane’s answer. If you want to enter u(E_t[x_{t+1}^y]) = 0 where u is nonlinear, you need two equations

``````u(z) = 0;
z=x(+1)^y;``````

The z in the first equation does not get a timing t+1, because the expectations operator at time t makes z belong to the information set at time t.

How can i write the code segment that differentiate:
[exp(-V(t+1)/Theta)] / Expectation_t[exp(-V(t+1)/Theta)]
I fear i will always get 1 due to expectation operator that dynare uses.

You can find an example of Epstein-Zin preferences at github.com/JohannesPfeifer/DSGE_mod/blob/master/Caldara_et_al_2012/Caldara_et_al_2012.mod
Note that you need to use `order>1`

Testing the code that you suggesti I simply defined another variable that give the ratio between [V(+1)^sigma] and E_t[V(+1)^sigma]. For this purpose i defined another variable f1 and after the code line:

```// Define an auxiliary variable s that captures E_t[V(+1)^sigma] s =V(+1)^(1-gamma);```

I have written:

``f1 =(V(+1)^(1-gamma))/s;``

Trying to take impulse response of the new variable f1, I observed that nothing changes in f1, which means that this auxiliary variable concept seems to not working.

Am i doing this wrong?

Thanks.
Caldara_test.mod (6.07 KB)

I am not sure what you were trying to test, but the f1 you defined is not supposed to change, because it is identical to 1.

My original problem was to seperate `V(+1)^(1-gamma)` and `E_t[V(+1)^(1-gamma)]`.
I want to see if there is anything different between the value of `V(+1)^(1-gamma)` and `s` which is defined as `E_t[V(+1)^(1-gamma)]`.
The code that you suggest find the ratio `V(+1)^(1-gamma)/E_t[V(+1)^(1-gamma)]` by defining s first than writing `V(+1)^(1-gamma)/s`. Hence, i tried to observe this ratio with new variable f1.

That’s not going to work. There is an expected value conditional on time t around every equation in Dynare. Therefore

``V(+1)^(1-gamma)/s=E_t(V(+1)^(1-gamma)/s)=1/s*E_t(V(+1)^(1-gamma))=1/s*s=1``

where you can pull s out of the expectations because it is contained in the information set. The trick is to have a nonlinear transformation of that ratio like

``(V(+1)^(1-gamma)/s)^(1-(1/theta))=E_t(V(+1)^(1-gamma)/s)^(1-(1/theta))]=(1/s)^(1-(1/theta))*E_t((V(+1)^(1-gamma))^(1-(1/theta)))~=1``

because due to Jensen’s inequality this is not equal to 1. In the first term

``(1/s)^(1-(1/theta))``

the expectation is inside of the “to the power of (1-(1/theta))”, while in

``E_t((V(+1)^(1-gamma))^(1-(1/theta)))``

it is around the term.

Thank you for the clear answer. I now understand how dynare expectation opeariton works. Considering this, i rearranged my code in which i have a similar form `exp(-V(+1)/chi)/E_t[exp(-V(+1)/chi)]` where chi is robustness parameter.
I have written above expression as `EV = -(V(+1)/chi);` and the original term is `exp((-V(+1)/chi)-EV)` where exp() is a nonlinear function as you suggest.
I was expecting to have different irf responses whenever i change the value of chi. Yet i always am taking the same irf with different chi values.
My first response was to check whether i have written the ratio in a correct way. Now i am sure about that part yet i am clearly doing something else wrong.
Does exp() function have another property rather than being nonlinear - like it takes expectation inside etc.- or am i missing something obvious.
Here is my code if you want to look at.
Thanks again.
Robust_Simple.mod (8.68 KB)

As mentioned in my first reply, you need
order>1
If you only do a linear approximation, all nonlinearities are gone.

I am sorry for that confusion but even if i change the order to 2 i obtain the same IRFs.
I will rebuild the code and inform the forum about the progress.

``````again has the expectations around both expressions and is identical to 1.
You are not using a nonlinear transformation of the expectations themselves.``````

again has the expectations around both expressions and is identical to 1.
You are not using a nonlinear transformation of the expectations themselves.

I believe i did the nonlinear transformation using the nonlinear function exp().

[code]EV = -(V(+1)/chi);

exp((-V(+1)/chi)-EV); [/code]
Does second line perform a nonlinear transformation right?

As a 2nd option i have written the expression at top as:

``(1 + (1/1)*(-V(+1)/chi-EV) + (1/2)*(-V(+1)/chi-EV)^2 + (1/6)*(-V(+1)/chi-EV)^3)``

(which is actually a 3rd order approximtion around 0) so that i can solve the model with order=2. The IRFs are still same.