# Anticipated vs unanticipated shocks

**URL:** <https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530>\
**Category:** Stochastic simulations\
**Created:** [27 December 2021 17:09 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530 "2021-12-27T17:09:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwlf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/e480ec/32.png) [@mwlf](https://forum.dynare.org/u/mwlf)\
**Post date:** [27 December 2021 17:09 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/1 "2021-12-27T17:09:30Z")

</div>

Hi all,

I have a question about this [linked code](https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_news_shock_model/RBC_news_shock_model.mod.) by Prof Pfeifer. In this example, we have one anticipated news shock and one unanticipated shock. If we were to specify two shocks where **both were unanticipated** (with still 8 periods in between), would this code be adapted as follows? (Q1)

**z=rhoz\*z(-1)+eps\_z\_surprise + eps\_z\_news;**

I guess my question is: is (-8) in line 89 (in the original code) specifying the _anticipated_ nature of the shocks? (Q2)

Relatedly, the following part of the code specifies the timing between the shocks, and it doesn’t inform us anything about anticipation bit. Is that right? (Q3)

shock\_matrix(1,strmatch(‘eps\_z\_news’,M\_.exo\_names,‘exact’)) = 1;  
shock\_matrix(1+8,strmatch(‘eps\_z\_surprise’,M\_.exo\_names,‘exact’)) = -1;

I hope my question(s) were clear. I just have not worked with anticipated shocks before, so I am trying to understand the notation and which part of the code brings us the anticipated bit (so I can change it).

Thank you so much for your guidance in advance,  
Ezgi

---

<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:** [28 December 2021 16:05 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/2 "2021-12-28T16:05:27Z")

</div>

1. To have an anticipated shock, you need to lag the shock. In the original code  
` z=rhoz*z(-1)+eps_z_surprise + eps_z_news(-8);`  
Here, `eps_z_news(-8)` indicates that the `eps_z_news` that became part of the information set at time t only affects z with a lag of 8 periods, i.e. is anticipated for 8 periods. If there were a second anticipated shock, simply have it lagged as well.
2. The `shock_matrix` specifies which shock (the columns) realizes at which point in time (periods are along the rows). It has nothing to do per se with anticipation.

---

<div class="post-metadata">

**Author:** ![mwlf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/e480ec/32.png) [@mwlf](https://forum.dynare.org/u/mwlf)\
**Post date:** [28 December 2021 17:32 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/3 "2021-12-28T17:32:18Z")

</div>

Exactly. Both of my shocks are _unanticipated_, so I guess that means I’ll remove the (-8) only and the rest is fine. Many thanks, Johannes!

Wish you happy holidays!  
Ezgi

---

<div class="post-metadata">

**Author:** ![Marie1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@Marie1](https://forum.dynare.org/u/Marie1)\
**Post date:** [13 February 2025 11:00 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/4 "2025-02-13T11:00:58Z")

</div>

Hey, I have a question similar to this one.

I have a stochastic model (NKM augmented by energy as production factor). I want to have an anticipated shock in which my agents know in period 0 when they awake that there is a energy price subsidy for 10 years of -10% starting 2 quarters later. Thus I want a value of -10% for period 2 to 42 (since it is quarterly). My impulse response to the energy price should be horizontal at -10% between period 2 and 42, for all other periods it should be 0. Can someone please give me a tip on how to implement this in dnyare?

Right now I only managed to get a two periods before anticipated AR(1) shock:  
%Law of motion for real energy price  
xi = gamma \* xi(-1) - v(-2);  
%shock  
shocks;  
var v = 10^2;  
end;

Thank you very much for your help!

Best,  
Marie

---

<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:** [14 February 2025 10:15 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/5 "2025-02-14T10:15:36Z")

</div>

Do you need to do a stochastic simulation for this? It sounds like a straightforward perfect foresight exercise.

---

<div class="post-metadata">

**Author:** ![Marie1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@Marie1](https://forum.dynare.org/u/Marie1)\
**Post date:** [17 February 2025 13:27 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/6 "2025-02-17T13:27:08Z")

</div>

Hey, thanks for your answer. My thought was that the agents only anticipate the energy price “shock”/subsidy but they do form beliefs for e.g. future inflation and output (gap) based on the new information. Thus I decided for the stochastic set-up. What would you have done? And what does this mean for my shock simulation?

---

<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 February 2025 19:23 UTC](https://forum.dynare.org/t/anticipated-vs-unanticipated-shocks/19530/7 "2025-02-17T19:23:01Z")

</div>

At first order, there will be certainty equivalence. I woud have gone for a perfect foresight simulation. In such models agents are still forward-looking. But they do not have precautionary behavior due to stochastic shocks potentially happening in the future.
