# Timing notation of model-local variables for portfolio choice

**URL:** <https://forum.dynare.org/t/timing-notation-of-model-local-variables-for-portfolio-choice/28091>\
**Category:** Stochastic simulations\
**Created:** [12 November 2025 09:28 UTC](https://forum.dynare.org/t/timing-notation-of-model-local-variables-for-portfolio-choice/28091 "2025-11-12T09:28:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanbasten](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/35a633/32.png) [@vanbasten](https://forum.dynare.org/u/vanbasten)\
**Post date:** [12 November 2025 09:28 UTC](https://forum.dynare.org/t/timing-notation-of-model-local-variables-for-portfolio-choice/28091/1 "2025-11-12T09:28:35Z")

</div>

Hello, I am a bit confused about the timing and expectation operator in dynare and how it is related to model local variables,. Suppose I have the following utility function u\left(c\_{t}\right)=\frac{\left(c\_{t}-hc\_{t-1}\right)^{1-\gamma}}{1-\gamma} and an asset (not risk free) with R\_{t}^{p} gross return for time t for asset purchased at time t-1. Then Euler eqn \left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}=\beta\mathbb{E}\_{t}\left[R\_{t+1}^{p}\left(\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}-\beta h\left(c\_{t+2}-hc\_{t+1}\right)^{-\gamma}\right)^{-\gamma}\right]

Which of the following is correct in dynare if I am doing 2nd - 3rd order simlations as in Basu-Bundick

#### Case-1 (with model-local variables)

```auto
model_local_variable
uc $mu_{t}$ (long_name='marginal utility at time t')
end;
model
#uc=((c-h*c(-1) -betta*h*(c(+1)-h*c))^(-gamma);
uc=betta*uc(+1)*Rp(+1);
end;

```

#### Case-2 (with model-local variables)

```auto
model
#util=c(+1)-h*c;
#uc=(util(-1) -betta*h*util)^(-gamma);
#uctp1=((util-betta*h*util(+1))^(-gamma))^(-gamma);
uc=betta*uc(+1)*Rp(+1);
end;

```

#### Case-3 (without model-local variables)

```auto
model
uc=(c-h*c(-1))^(-gamma)-betta*h*(c(+1)-h*c)^(-gamma);
uc=betta*uc(+1)*Rp(+1);
end;

```

Thank you

---

<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:** [13 November 2025 09:20 UTC](https://forum.dynare.org/t/timing-notation-of-model-local-variables-for-portfolio-choice/28091/2 "2025-11-13T09:20:17Z")

</div>

1. You have various inconsistencies/typos in your equations. The -\gamma exponent is often missing.
2. Your Euler equation formula is missing the expected value on the left hand side for the internal habit part.
3. The first two specifications are equivalent in Dynare (apart from the typos). You can see that by plugging in. They must return the same results.
4. The fourth one is problematic because it will not have the correct timing due to `uc` containing an expected value.

---

<div class="post-metadata">

**Author:** ![vanbasten](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/35a633/32.png) [@vanbasten](https://forum.dynare.org/u/vanbasten)\
**Post date:** [15 November 2025 08:40 UTC](https://forum.dynare.org/t/timing-notation-of-model-local-variables-for-portfolio-choice/28091/3 "2025-11-15T08:40:32Z")

</div>

Thank you for the answer. But I am extremely confused and having doubts if dynare can actually deal with habits, adjustment costs etc in 2nd and 3rd order. Or maybe I am confusing the basics. Below I try to explain my confusion, especially this expectation operator in dynare and whether model-local variables can include leads

Suppose I have the following u\left(c\_{t}\right)=\frac{\left(c\_{t}-hc\_{t-1}\right)^{1-\gamma}}{1-\gamma} and an asset (not risk free) with R\_{t}^{p} gross return for time t for asset purchased at time t-1. Then Euler eqn  
 \left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\mathbb{E}\_{t}\left[\beta h\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]=\beta\mathbb{E}\_{t}\left[R\_{t+1}^{p}\left(\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}-\beta h\left(c\_{t+2}-hc\_{t+1}\right)^{-\gamma}\right)^{-\gamma}\right]

# CASE-1 Model-Local variables

> model
> 
> `#uc=( (c-h*c(-1)^(-gamma) -betta*h*(c(+1)-h*c) )^(-gamma);`  
> \underbrace{\left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\mathbb{E}\_{t}\left[\beta h\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]}\_{\text{uc}}
> 
> `uc=betta*uc(+1)*Rp(+1);` \underbrace{\left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]}\_{\text{uc}}=\beta\mathbb{E}\_{t}\left[R\_{t+1}^{p}\left[\underbrace{\left(c\_{t+1}-hc\_{t}\right)-\mathbb{E}\_{t}\left[\beta h\left(c\_{t+2}-hc\_{t+1}\right)^{-\gamma}\right]}\_{\text{uc(+1)}}\right]\right]
> 
> end;

# CASE-2 Model-Local variables

> `model`
> 
> `#util=(c(+1)-h*c);`  
> util=\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]
> 
> `#uc=( util(-1)^(-gamma) -betta*h*util^(-gamma) );`  
> uc=\left(\underbrace{c\_{t}-hc\_{t-1}}\_{\text{util(-1)}}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(\underbrace{\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]}\_{\text{util(+1)}}\right)^{-\gamma}\right]
> 
> `#uctp1=(( util^(-gamma)-betta*h*(util(+1))^(-gamma) );`
> 
> uctp1=\underbrace{\left(\overbrace{\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]}^{\text{util}}\right)^{-\gamma}}\_{\text{util to (-gamma)}}-\beta h\mathbb{E}\_{t}\left[\underbrace{\left(\overbrace{\mathbb{E}\_{t}\left[c\_{t+2}-hc\_{t+1}\right]}^{\text{util(+1)}}\right)^{-\gamma}}\_{\text{util(+1) to (-gamma)}}\right]
> 
> \left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]\right)^{-\gamma}\right]=\beta\mathbb{E}\_{t}\left[R\_{t+1}^{p}\left[\left(\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]\right)^{-\gamma}-\mathbb{E}\_{t}\left[\beta h\left(\mathbb{E}\_{t}\left[c\_{t+2}-hc\_{t+1}\right]\right)^{-\gamma}\right]\right]\right]
> 
> `uc=betta*uc(+1)*Rp(+1);`
> 
> \left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]\right)^{-\gamma}\right]=\beta\mathbb{E}\_{t}\left[R\_{t+1}^{p}\left[\left(\mathbb{E}\_{t}\left[c\_{t+1}-hc\_{t}\right]\right)^{-\gamma}-\mathbb{E}\_{t}\left[\beta h\left(\mathbb{E}\_{t}\left[c\_{t+2}-hc\_{t+1}\right]\right)^{-\gamma}\right]\right]\right]
> 
> end;

# CASE-3 Without Model-Local variables, only Var block

> model  
> uc=(c-h_c(-1))^(-gamma)-betta_h\*(c(+1)-h\*c)^(-gamma);  
> uc=\left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]  
> uc=betta\*uc(+1)\*Rp(+1);  
> \left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]=\beta\mathbb{E}\_{t}\left[\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}-\beta h\mathbb{E}\_{t}\left[\left(c\_{t+2}-hc\_{t+1}\right)^{-\gamma}\right]\right]  
> end;

---

<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:** [17 November 2025 21:18 UTC](https://forum.dynare.org/t/timing-notation-of-model-local-variables-for-portfolio-choice/28091/4 "2025-11-17T21:18:57Z")

</div>

You are confusing what a model-local variable does. It will simply plug in the text expression at the place it is encountered. It will not define a new variable in the information set at time t, which would contain an expectation.  
Thus,  
`#uc=( (c-h*c(-1)^(-gamma) -betta*h*(c(+1)-h*c) )^(-gamma);`  
means plugging in  
\underbrace{\left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\left[\beta h\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]}\_{\text{uc}}  
such that  
`uc=betta*uc(+1)*Rp(+1);`  
corresponds to  
\mathbb{E}\_{t} \left[\underbrace{\left(c\_{t}-hc\_{t-1}\right)^{-\gamma}-\beta h\left[\left(c\_{t+1}-hc\_{t}\right)^{-\gamma}\right]}\_{\text{uc}}\right]=\beta\mathbb{E}\_{t}\left[R\_{t+1}^{p}\left[\underbrace{\left(c\_{t+1}-hc\_{t}\right)-\left[\beta h\left(c\_{t+2}-hc\_{t+1}\right)^{-\gamma}\right]}\_{\text{uc(+1)}}\right]\right]

You can easily check the output by investigating the \LaTeX output from `write_latex_dynamic_model`.
