[share] shock contributions labels and groups

I run a medium scale model for my thesis with a lot of shocks. I needed to group them to make the shock contribution more clear than the current way it’s showed by dynare.

To do so, download attached dynare files and put them in /dynare/matlab/ folder. For instance, when using the Smets & Wouters model given by jpfeifer Smets/Wouters (2007) in Dynare 4.2.5 , adding at the end of the mod file :

options_.groups{1}={'ea';'epinf'}; options_.groups{2}={'eg';'eb';'ew'}; options_.groups{3}={'em';'eqs'}; options_.labels = char( 'Supply', 'Demand', 'Monetary' ); shock_decomposition y;

this will aggregate the shocks by the given groups (those given in the example are dummy). if options_.labels is not given, the code will automatically generate some group names.


I wanted to edit dynare argument of the function shock_decomposition(), but i couldnt (dynare was giving me an error). I guess that some important dynare internal functions are declared in dynare.exe, my hex editor told me so (but i cannot edit it, i’m not a C coder).
shock_decomposition.m (3.09 KB)
graph_decomp.m (3.81 KB)

First of all, you don’t need to deal with C-code. Everything here is done in Matlab. Second, the whole shock decomposition is stored in oo_.shock_decomposition. Thus, you could just use this information for graphing.

Hi all,
I´m trying to do the same decomposition metioned previously, but I didn´t understand where should I place the part of the code below:
options_.labels = char( ‘Supply’, ‘Demand’, ‘Monetary’ );

Is it before or inside the estimation comand ? Or is it inside the shock_decomposition comand ?

I did a research about this in the forum, but I didn´t find the answer.

Thanks for the attention.

before the shock decomposition command

Hi Frederico,

I know this should be posted in the help part of the forum, but could you take a look and say what is wrong with the part of the code below? I got an “unexpected name” message from dynare, refering to the shock command inside the shock_decompositon command.

options_.labels = char( ‘supply’, ‘demand’, ‘monetary’,‘external’);

stoch_simul(irf=0) y_hat, picz_hat, rer_hat, l_hat, ca_y_hat, i_hat, c_hat, inv_hat;

shock_decomposition(parameter_set = calibration, shocks= (options_.groups{1};options_.groups{2};options_.groups{3};
options_.groups{4}) ,labels= options_.labels)

y_hat, picz_hat, rer_hat, l_hat, ca_y_hat wr_hat c_hat inv_hat pri_hat;

try to move all the label afetr stoch_simul
and simply use the command shock_decomposition without any other option and see if it works.

Besides, I remember i had same troubles in running this options with dynare > 4.3 version.
I succesfully ues it with dynare 4.2.5 .

If it does’t work i think you should post your mod file and see what i can do.

here is attached an example file with Smets & Wouters codes.
Smets_Wouters_2007_Dynare425.zip (22.8 KB)

Hi Vermandel and Frederico,

I think this problem is related with the dynare version, because I ran the code above and got the chart without the labels. I´m using dynare 4.3.3. Which version are you using, Vermandel?

It works surely under dynare version 4.2.5


I am working with dynare 4.3.3 version.
I got,

Starting Dynare (version 4.3.3).
Starting preprocessing of the model file …
ERROR: nonlinearomega.mod:1713.48-53: syntax error, unexpected NAME, expecting DATAFILE or LABELS or PARAMETER_SET or SHOCKS

What is unexpected since in nonlinearomega.mod:1713.48-53 I already have SHOCKS ( for confirmation, please, see the file above).
Is this a bug?
nonlinearomega-2 2 USA 2.zip (554 KB)

Sorry, but this is no supported function of Dynare. If the original author does not help you out, you will have to solve this yourself.

Thank you. I already solved it myself!