# Shock Decompositions in Julia

Hello, I’m attempting to do historical cumulated shock decompositions in Julia similar to those done in Matlab’s Dynare (attached an example below). Not sure as to how to go about doing this? Using Plots.jl to match up each y-value and individually creating data frames for each set of stacks is proving to be very cumbersome and inefficient. Any help would be appreciated, thanks.

Not really sure what that is, but check https://github.com/JuliaPlots/StatsPlots.jl#grouped-bar-plots

Hi, yes this is what I was referring to: creating data frames for individual sets of stacks for 200 periods of time and several parameters (i.e. shocks here) that are decomposed cumulatively is turning out to be very inefficient. In Dynare for example, since it’s built for these DSGE models in economics, there already exist several functions/packages that do so, and I was wondering if there are easier or more effective ways of doing so. In my figure, for example, I’m decomposing the 11 shocks that affect a variable so as to see their sizes proportional to the cumulated aggregate effect.

If you need help plotting something like this, a self-contained MWE that generates the data could be helpful.

I’m not 100% clear on what your chart is doing - @mkborregaard’s suggestion is for a stacked bar, but it seems to me like your original chart just overlays a bunch of separate bar charts, all starting from the origin, with an additional line chart showing the net effect?

Examples:

``````using StatsPlots

shocks = hcat(2*rand(100), -rand(100), 0.5*rand(100))
shock_names = ["alpha", "beta", "gamma"]

total_impact = sum(shocks, dims = 2)

groupedbar(shocks, bar_position = :stack, labels = shock_names)
``````

or alternatively, if you’re overlaying histograms and plotting a separate total:

``````p = plot()

for (i, s) ∈ enumerate(eachcol(shocks))
bar!(p, s, label = shock_names[i])
end

plot!(p, total_impact, label = "Total impact", linewidth=3, color = "black")
``````

although in the latter case you might want to turn down the `alpha` to make overlaid series visible!

This was perfect, thanks a lot!