This guide explains how to use the godley
package to
create the SIM model, the simplest model with government money, as
described by Wynne Godley and Marc Lavoie in Chapter 3
of Monetary Economics: An Integrated Approach to Credit, Money,
Income, Production and Wealth.
Base scenario
Start by initializing an empty SFC (Stock-Flow Consistent) model:
# Create empty model
model_sim <- create_model(name = "SFC SIM")
#> Empty model created
Define the variables for the model:
# Add variables
model_sim <- model_sim |>
add_variable("C_d", desc = "Consumption demand by households") |>
add_variable("C_s", desc = "Consumption supply") |>
add_variable("G_s", desc = "Government supply") |>
add_variable("H_h", desc = "Cash money held by households") |>
add_variable("H_s", desc = "Cash money supplied by the government") |>
add_variable("N_d", desc = "Demand for labor") |>
add_variable("N_s", desc = "Supply of labor") |>
add_variable("T_d", desc = "Taxes, demand") |>
add_variable("T_s", desc = "Taxes, supply") |>
add_variable("Y", desc = "Income = GDP") |>
add_variable("Yd", desc = "Disposable income of households") |>
add_variable("alpha1", init = 0.6, desc = "Propensity to consume out of income") |>
add_variable("alpha2", init = 0.4, desc = "Propensity to consume out of wealth") |>
add_variable("theta", init = 0.2, desc = "Tax rate") |>
add_variable("G_d", init = 20, desc = "Government demand") |>
add_variable("W", init = 1, desc = "Wage rate")
Establish the relationships between variables by adding equations:
# Add equations
model_sim <- model_sim |>
add_equation("C_s = C_d", desc = "Consumption") |>
add_equation("G_s = G_d") |>
add_equation("T_s = T_d") |>
add_equation("N_s = N_d") |>
add_equation("Yd = W * N_s - T_s") |>
add_equation("T_d = theta * W * N_s") |>
add_equation("C_d = alpha1 * Yd + alpha2 * H_h[-1]") |>
add_equation("H_s = G_d - T_d + H_s[-1]") |>
add_equation("H_h = Yd - C_d + H_h[-1]") |>
add_equation("Y = C_s + G_s") |>
add_equation("N_d = Y/W") |>
add_equation("H_s = H_h", desc = "Money equilibrium", hidden = TRUE)
Now, you can simulate the model (in this example, we calculate the baseline scenario over 100 periods using the Newton method)
# Simulate model
model_sim <- simulate_scenario(model_sim,
scenario = "baseline", max_iter = 350, periods = 100,
hidden_tol = 0.1, tol = 1e-05, method = "Newton"
)
#> Model prepared successfully
#> Simulating scenario baseline (1 of 1)
#> Scenario(s) successfully simulated
With the simulation estimated, visualize the results for the variables of interest:
# Plot results
plot_simulation(
model = model_sim, scenario = c("baseline"), from = 1, to = 50,
expressions = c("Y", "C_d", "G_s")
)
Note: The above example uses the new pipe operator
(|>
), which requires R 4.1 or later.
Shock scenario
With godley
package you can simulate how shocks affect
the economy (specifically, how they impact the base scenario).
In this example, we apply a permanent increase in government expenditures.
First, initialize an empty shock object:
# Create empty shock
shock_sim <- create_shock()
#> Shock object created
Define the shock by adding an appropriate equation:
# Add shock equation with increased government expenditures
shock_sim <- add_shock(shock_sim,
variable = "G_d",
value = 25,
desc = "Increase in government expenditures", start = 5, end = 50
)
Integrate the shock into the model by creating a new scenario:
# Create new scenario with this shock
model_sim <- add_scenario(model_sim,
name = "expansion", origin = "baseline", shock = shock_sim
)
Simulate the scenario with the shock applied:
# Simulate shock
model_sim <- simulate_scenario(model_sim,
scenario = "expansion", max_iter = 350, periods = 100,
hidden_tol = 0.1, tol = 1e-05, method = "Newton"
)
#> Simulating scenario expansion (1 of 1)
#> Scenario(s) successfully simulated
Finally, compare the results of the base scenario with those of the shock scenario.
# Plot results
plot_simulation(
model = model_sim, scenario = c("baseline", "expansion"), from = 1, to = 50,
expressions = c("Y")
)
plot_simulation(
model = model_sim, scenario = c("baseline", "expansion"), from = 1, to = 50,
expressions = c("C_d")
)
plot_simulation(
model = model_sim, scenario = c("baseline", "expansion"), from = 1, to = 50,
expressions = c("G_s")
)