knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This guide explains how to use the godley
package to create the BMWK model — a Kaldorian model with private bank money described by Wynne Godley and Marc Lavoie in Chapter 7 of Monetary Economics. An Integrated Approach to Credit, Money, Income, Production and Wealth.
library(godley)
Start by creating an empty SFC model:
# Create empty model model_bmwk <- create_model(name = "SFC BMWK")
Define the variables for the model:
# Add variables model_bmwk <- model_bmwk |> add_variable("rl", init = 0.025) |> add_variable("alpha0", init = 20) |> add_variable("alpha2", init = 0.10) |> add_variable("delta", init = 0.10) |> add_variable("gamma", init = 0.15) |> add_variable("kappa", init = 1) |> add_variable("pr", init = 1) |> add_variable("Nd", init = .001) |> add_variable("Ns", init = .001) |> add_variable("Y", init = .001) |> add_variable("alpha1w", init = .8) |> add_variable("alpha1r", init = .15) |> add_variable("Cs") |> add_variable("Cd") |> add_variable("Is") |> add_variable("Id") |> add_variable("Ls") |> add_variable("Ld") |> add_variable("WBd") |> add_variable("AF") |> add_variable("K") |> add_variable("YD") |> add_variable("WBs") |> add_variable("rm") |> add_variable("Mh") |> add_variable("Ms") |> add_variable("W") |> add_variable("DA") |> add_variable("KT")
Establish the relationships between variables by adding equations:
# Add equations model_bmwk <- model_bmwk |> add_equation("Cs = Cd") |> add_equation("Is = Id") |> add_equation("Ns = Nd") |> add_equation("Ls = Ls[-1] + Ld - Ld[-1]") |> add_equation("Y = Cs + Is") |> add_equation("WBd = Y - rl[-1] * Ld[-1] - AF") |> add_equation("AF = delta * K[-1]") |> add_equation("Ld = Ld[-1] + Id - AF") |> add_equation("YD = WBs + rm[-1] * Mh[-1]") |> add_equation("Mh = Mh[-1] + YD - Cd") |> add_equation("Ms = Ms[-1] + Ls - Ls[-1]") |> add_equation("rm = rl") |> add_equation("WBs = W * Ns") |> add_equation("Nd = Y / pr") |> add_equation("W = WBd / Nd") |> add_equation("Cd = alpha0 + alpha1w * WBs + alpha1r * rm[-1] * Mh[-1] + alpha2 * Mh") |> add_equation("K = K[-1] + Id - DA") |> add_equation("DA = delta * K[-1]") |> add_equation("KT = kappa * Y[-1]") |> add_equation("Id = gamma * (KT - K[-1]) + DA") |> add_equation("Ms = Mh", hidden = TRUE)
Now, you can simulate the model (in this example, the baseline scenario over 100 periods using the Gauss method):
# Simulate model model_bmwk <- simulate_scenario(model_bmwk, scenario = "baseline", max_iter = 350, periods = 100, hidden_tol = 0.1, tol = 1e-08, method = "Gauss" )
With the simulation estimated, you can create a plot to visualize the results for the variables of interest:
# Plot results plot_simulation( model = model_bmwk, scenario = c("baseline"), from = 1, to = 50, expressions = c("Y") )
Note: The above example uses the new pipe operator (|>
), which requires R 4.1 or later.
With godley
package we can simulate how shocks affect the economy (specifically, how they impact the base scenario).
In this example, we simulate the effect of an increase in the interest rate.
First, initialize an empty shock object:
# Create empty shock shock_bmwk <- create_shock()
Define the shock by adding an appropriate equation:
# Add shock equation shock_bmwk <- add_shock(shock_bmwk, variable = "rl", value = 0.035, desc = "Increase in the interest rate", start = 5, end = 50 )
Integrate the shock into the model by creating a new scenario:
# Create new scenario with this shock model_bmwk <- add_scenario(model_bmwk, name = "expansion", origin = "baseline", origin_start = 1, origin_end = 100, shock = shock_bmwk )
Simulate the scenario with the shock applied:
# Simulate shock model_bmwk <- simulate_scenario(model_bmwk, scenario = "expansion", max_iter = 350, periods = 100, hidden_tol = 0.1, tol = 1e-08, method = "Gauss" )
Plot the simulation outcomes:
# Plot results plot_simulation( model = model_bmwk, scenario = c("expansion"), from = 1, to = 50, expressions = c("Y") )
For more details on BMWK model, refer to Chapter 7 of Monetary Economics. An Integrated Approach to Credit, Money, Income, Production and Wealth.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.