Page 1 of 2

Expected value of a power

PostPosted: Fri Oct 14, 2011 2:03 pm
by Fab.valenti
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

Re: Expected value of a power

PostPosted: Thu Oct 27, 2011 4:05 pm
by SébastienVillemot
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,

Re: Expected value of a power

PostPosted: Thu Oct 27, 2011 8:07 pm
by jpfeifer
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 http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=2997. From my experience, using this type of auxiliary variable works in Dynare.

Re: Expected value of a power

PostPosted: Mon Nov 07, 2011 5:23 pm
by StephaneAdjemian
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.

Re: Expected value of a power

PostPosted: Thu Nov 17, 2011 9:26 am
by Fab.valenti
Thank you all for your answers.

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

Best,

Fabrizio

Re: Expected value of a power

PostPosted: Fri Feb 10, 2012 8:08 am
by jpfeifer
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
Code: Select all
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.

Re: Expected value of a power

PostPosted: Sun Dec 04, 2016 5:33 pm
by farukakbal
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.

Re: Expected value of a power

PostPosted: Sun Dec 04, 2016 5:38 pm
by jpfeifer
You can find an example of Epstein-Zin preferences at https://github.com/JohannesPfeifer/DSGE_mod/blob/master/Caldara_et_al_2012/Caldara_et_al_2012.mod
Note that you need to use
Code: Select all
order>1

Re: Expected value of a power

PostPosted: Wed Dec 14, 2016 10:34 pm
by farukakbal
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:
Code: Select all
// Define an auxiliary variable s that captures E_t[V(+1)^sigma]
s =V(+1)^(1-gamma);


I have written:
Code: Select all
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.

Re: Expected value of a power

PostPosted: Thu Dec 15, 2016 8:45 am
by jpfeifer
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.

Re: Expected value of a power

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

Re: Expected value of a power

PostPosted: Wed Dec 21, 2016 7:56 am
by jpfeifer
That's not going to work. There is an expected value conditional on time t around every equation in Dynare. Therefore
Code: Select all
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
Code: Select all
(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
Code: Select all
(1/s)^(1-(1/theta))

the expectation is inside of the "to the power of (1-(1/theta))", while in
Code: Select all
E_t((V(+1)^(1-gamma))^(1-(1/theta)))

it is around the term.

Re: Expected value of a power

PostPosted: Wed Dec 21, 2016 12:56 pm
by farukakbal
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
Code: Select all
exp(-V(+1)/chi)/E_t[exp(-V(+1)/chi)]
where chi is robustness parameter.
I have written above expression as
Code: Select all
EV = -(V(+1)/chi);
and the original term is
Code: Select all
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.

Re: Expected value of a power

PostPosted: Wed Dec 21, 2016 1:23 pm
by jpfeifer
As mentioned in my first reply, you need
[url]order>1[/url]
If you only do a linear approximation, all nonlinearities are gone.

Re: Expected value of a power

PostPosted: Wed Dec 21, 2016 2:49 pm
by farukakbal
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.