# How to apply both shocks to the model

**URL:** <https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246>\
**Category:** Stochastic simulations\
**Created:** [6 January 2021 08:29 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246 "2021-01-06T08:29:19Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [6 January 2021 08:29 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/1 "2021-01-06T08:29:19Z")

</div>

Dear Dynare members，  
I am a Dynare novice and have been doing some Dynare exercises recently. I want to make a superposition shock, which means to add a money supply shock to the labor shock, but I use the following command to realize the independent influence of the above two shocks on the variables.  
The orders I use are as follows:

> shocks;  
> var eN;  
> stderr 1;  
> var em;  
> stderr 0.1;  
> end;

Finally, please let me describe my problem again，I want to make a model that includes the simultaneous superposition of labor and money supply shocks, and show the results of the two shocks on a graph. This is my model file[simulation\_a.mod](https://forum.dynare.org/uploads/short-url/oI8nsl3RDkDdjYoPR6nywOyejfC.mod) (3.0 KB) .Looking forward to your reply!

---

<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:** [6 January 2021 09:16 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/2 "2021-01-06T09:16:20Z")

</div>

You can do this using the `simult_`-function. See [https://github.com/JohannesPfeifer/DSGE\_mod/blob/master/RBC\_news\_shock\_model/RBC\_news\_shock\_model.mod](https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_news_shock_model/RBC_news_shock_model.mod) for an example.  
But note that at first order, the IRF to a joint shock is simply the sum of the IRFs to the individual shocks due to linearity.

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [7 January 2021 02:42 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/3 "2021-01-07T02:42:54Z")

</div>

Thank you for your reply， I made some changes to the code you provided, but the result was a little strange, and I don’t understand which code is fulfilling my requirements：

> 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;  
> y2 = simult\_(M\_,options\_,initial\_condition\_states,oo\_.dr,shock\_matrix,1);  
> y\_IRF = y2(:,M\_.maximum\_lag+1:end)-repmat(oo\_.dr.ys,1,options\_.irf);  
> figure  
> subplot(2,1,1)  
> plot(y\_IRF(strmatch(‘y’,M\_.endo\_names,‘exact’),:));  
> title(‘Output’);  
> subplot(2,1,2)  
> plot(y\_IRF(strmatch(‘z’,M\_.endo\_names,‘exact’),:));  
> title(‘TFP’);

The above code produces a diagram，is this a picture of the impact offset，or is the following set of code？

> figure  
> for ii=1:M\_.orig\_endo\_nbr  
> subplot(3,3,ii)  
> if max(abs(y\_IRF(ii,:)))\>1e-12 %get rid of numerical inaccuracies 消除数值误差  
> plot(y\_IRF(ii,:));  
> else  
> plot(zeros(options\_.irf,1));  
> end  
> title(deblank(M\_.endo\_names(ii,:)));  
> end

My last question is, what does the above two code-generated diagrams mean？

This is my code[simulation\_a.mod](https://forum.dynare.org/uploads/short-url/2JwZCgTPtCokiNiSsI5gyrcrajJ.mod) (4.3 KB)  
The graphics generated by my two pieces of code are also very strange, and I want to know the reason.  
Thank you again！

---

<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:** [7 January 2021 08:37 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/4 "2021-01-07T08:37:25Z")

</div>

You need to set

```auto
shock_matrix(1,strmatch('eN',M_.exo_names,'exact')) = 1; 
shock_matrix(1,strmatch('em',M_.exo_names,'exact')) = 0.1; 

```

Both shocks are supposed to happen in the first period. You also need to adjust the number of subplots. See  
[simulation\_a.mod](https://forum.dynare.org/uploads/short-url/8DkBbvOqCzup6Eo1fKKhzKWOnXs.mod) (4.3 KB)

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [7 January 2021 09:32 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/5 "2021-01-07T09:32:18Z")

</div>

Professor Feifer, thank you for your reply. After running the code you sent me, I have two questions, one is in picture 3, there are some subgraphs not listed, what is the reason?

 ![picture 3](https://forum.dynare.org/uploads/default/original/2X/1/1b6e6c74fd7027e3c44ee4e13d5383357f7e486d.jpeg)  
Two is what does picture 3 and picture 4 explain respectively?  
 ![picture 4](https://forum.dynare.org/uploads/default/original/2X/a/a02d0d43643184d273d6bc3282e9c740ac8d7db6.jpeg)

---

<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:** [7 January 2021 12:14 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/6 "2021-01-07T12:14:29Z")

</div>

1. You did not adjust the subplots correctly:

```auto
subplot(3,2,2)
plot(y_IRF(strmatch('Y',M_.endo_names,'exact'),:));
title('Output');
subplot(3,2,2)
plot(y_IRF(strmatch('K',M_.endo_names,'exact'),:));
title('Captial');

```

uses the second plot twice instead of using the third one.  
2. Your “Picture 3” is the IRFs of the variables you selected while “Picture 4” is the IRFs for all variables.

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [7 January 2021 13:35 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/7 "2021-01-07T13:35:44Z")

</div>

Thank you very much for your reply. I would like to say what I understand now: picture 3 and picture 4 are all pictures of joint impact, but picture 3 is my choice, picture 4 is all variables,

---

<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:** [7 January 2021 18:53 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/8 "2021-01-07T18:53:55Z")

</div>

Yes, that is correct.

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [8 January 2021 04:19 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/9 "2021-01-08T04:19:09Z")

</div>

Thank you very much for your reply！

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [8 January 2021 05:10 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/10 "2021-01-08T05:10:38Z")

</div>

Dear Professor Feifer,  
I encountered a new problem in my work, I divided the size of the currency shock em in the mixed shock into three different values ,0.1,0.5 and 1, respectively, and I wanted to draw these three different situations on a graph.  
I wrote a code that works well when combining the IRF of a labor shock eN with different values, as shown below：

 ![eN](https://forum.dynare.org/uploads/default/original/2X/9/9b6a6cfd8f85146a10521f6ff2b85341211fca0a.jpeg)  
When I used the same code to describe a composite impact diagram, there was a problem, and the result showed that it did not draw a different combination impact on a diagram  
 ![mix](https://forum.dynare.org/uploads/default/original/2X/8/8e3404aac126d05d2241c2a28f6bd2c6218fa23f.jpeg)  
So, what’s wrong with my code? what factors cause my combination impact of the IRF map can not be drawn together?  
Finally I will provide my model file，This is the model file I can implement for labor shocks[eN.zip](https://forum.dynare.org/uploads/short-url/qPO3B5jxyb3jbRo6OPQL9mKvNun.zip) (5.3 KB)  
This is the model file I can’t implement for mix shocks[mix.zip](https://forum.dynare.org/uploads/short-url/23nMcfDry22l4PD3ZRPRnCNAVv1.zip) (10.0 KB)  
Looking forward to your reply！

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [9 January 2021 00:51 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/11 "2021-01-09T00:51:19Z")

</div>

Could anyone help me?

---

<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:** [9 January 2021 08:12 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/12 "2021-01-09T08:12:35Z")

</div>

You are trying to use Dynare’s buitin IRFs when you try to load `outputc = oo_.irfs`. But you created IRFs yourself and stored them in e.g. `y_IRF(strmatch('pi',M_.endo_names,'exact'),:)`. That cannot work.

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [9 January 2021 13:17 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/13 "2021-01-09T13:17:44Z")

</div>

Thank you for your reply. Perhaps because I am a Dynare novice, I have no idea. Could you say something more？Many many many Thanks!

---

<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:** [9 January 2021 13:52 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/14 "2021-01-09T13:52:52Z")

</div>

It should be something like

```auto
load('m2_a_results.mat')
outputa = y_IRF

load('m2_b_results.mat')
outputb = y_IRF

load('m2_c_results.mat')
outputc = y_IRF

%load('simulation_a_results.mat')
%outputd = oo_.irfs

 t=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40]';

var_names={'C','Consumption'
    'Y','Output'
    'K','Capital'};

for var_iter=1:size(var_names,1)
   subplot(3,2,var_iter);
   plot(t,outputa(strmatch(var_names(var_iter,1),M_.endo_names,'exact'),:),'- k',t,outputb(strmatch(var_names(var_iter,1),M_.endo_names,'exact'),:),'--k',t,outputc(strmatch(var_names(var_iter,1),M_.endo_names,'exact'),:),':k')%,t,outputd.C_eN,':k')
   title(var_names(var_iter,2));
end

```

---

<div class="post-metadata">

**Author:** ![chenxin](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@chenxin](https://forum.dynare.org/u/chenxin)\
**Post date:** [11 January 2021 06:15 UTC](https://forum.dynare.org/t/how-to-apply-both-shocks-to-the-model/17246/15 "2021-01-11T06:15:32Z")

</div>

Thank you very much, Professor jpfeifer. I’ve done it.
