We can use the Solow Growth Model as a simple example, which assumes that output (GDP) is determined by the Cobb-Douglas production function:
Where:
- is the output at time ,
- is the level of technology (or productivity),
- is the labor input,
- is the capital's share of income.
Breakdown of Key Variables:
- Savings rate (s): Determines how much of the economy’s output is invested back into capital. Higher savings rates lead to higher levels of capital and output in the steady state.
- Depreciation rate (δ): Capital wears out over time, and the economy must invest enough to replace depreciated capital.
- Technological progress (γ): The key driver of long-term economic growth. Technological improvements increase productivity, allowing the economy to produce more output with the same inputs.
- Labor growth (η): Population and labor force growth influence how fast the economy needs to accumulate capital to keep up with a growing workforce.
Steps to Simulate Economic Growth:
- Define Initial Parameters: Set initial values for capital, labor, and productivity.
- Simulate Growth Over Time: Use equations to update capital, labor, and productivity at each time step.
- Plot the Results: Visualize the simulated economic growth using
ggplot2
.
CODE:
# Load necessary libraries
library(ggplot2)
# Set initial parameters for the simulation
alpha <- 0.33 # Capital share of income
beta <- 0.02 # Productivity growth rate
savings_rate <- 0.2 # Savings rate
depreciation <- 0.05 # Depreciation rate
labor_growth <- 0.01 # Labor growth rate
time_periods <- 100 # Simulation time horizon
# Initialize variables
A <- 1 # Initial productivity level
K <- 1 # Initial capital stock
L <- 1 # Initial labor input
gdp <- numeric(time_periods) # Vector to store GDP values over time
# Simulate growth over time using Solow model
for (t in 1:time_periods) {
# Calculate GDP using Cobb-Douglas production function
Y <- A * K^alpha * L^(1 - alpha)
gdp[t] <- Y
# Update capital, productivity, and labor for the next period
K <- (1 - depreciation) * K + savings_rate * Y # Capital accumulation
A <- A * (1 + beta) # Productivity growth
L <- L * (1 + labor_growth) # Labor growth
}
# Create a data frame for plotting
data <- data.frame(
Time = 1:time_periods,
GDP = gdp
)
# Plot the GDP growth over time using ggplot2
ggplot(data, aes(x = Time, y = GDP)) +
geom_line(color = "blue", size = 1) +
labs(title = "Simulated Economic Growth (Solow Model)",
x = "Time Period",
y = "GDP") +
theme_minimal()
We can create shiny interactive dashboards!
# Load necessary libraries
library(shiny)
library(ggplot2)
# Define UI for the Solow Growth Model Dashboard
ui <- fluidPage(
# App title
titlePanel("Solow Growth Model Simulation"),
# Sidebar layout with input controls
sidebarLayout(
# Sidebar panel for inputs
sidebarPanel(
# Slider input for savings rate
sliderInput("savings_rate",
"Savings Rate (s):",
min = 0.05,
max = 0.5,
value = 0.2,
step = 0.01),
# Slider input for depreciation rate
sliderInput("depreciation_rate",
"Depreciation Rate (δ):",
min = 0.01,
max = 0.1,
value = 0.05,
step = 0.01),
# Slider input for labor growth rate
sliderInput("labor_growth",
"Labor Growth Rate (n):",
min = 0.005,
max = 0.05,
value = 0.01,
step = 0.001),
# Slider input for technological growth rate
sliderInput("tech_growth",
"Technological Growth Rate (g):",
min = 0.01,
max = 0.05,
value = 0.02,
step = 0.001)
),
# Main panel for displaying the GDP plot
mainPanel(
plotOutput("gdpPlot") # Output plot
)
)
)
# Define server logic for the Solow Growth Model
server <- function(input, output) {
# Reactive expression to simulate GDP over time based on user inputs
solowModel <- reactive({
# Parameters from user inputs
alpha <- 0.33 # Capital share of income
s <- input$savings_rate # User-defined savings rate
delta <- input$depreciation_rate # User-defined depreciation rate
n <- input$labor_growth # User-defined labor growth rate
g <- input$tech_growth # User-defined technological growth rate
time_periods <- 100 # Time horizon
# Initialize variables
A <- 1 # Initial productivity
L <- 1 # Initial labor
K <- 1 # Initial capital
gdp <- numeric(time_periods) # Vector to store GDP values
# Simulate the Solow model over time
for (t in 1:time_periods) {
Y <- A * K^alpha * L^(1 - alpha) # Cobb-Douglas production function
gdp[t] <- Y # Store GDP
# Capital accumulation and updates for next period
K <- (1 - delta) * K + s * Y
A <- A * (1 + g) # Productivity grows
L <- L * (1 + n) # Labor grows
}
# Return the GDP data
data.frame(Time = 1:time_periods, GDP = gdp)
})
# Render the GDP plot
output$gdpPlot <- renderPlot({
data <- solowModel()
# Plot using ggplot2
ggplot(data, aes(x = Time, y = GDP)) +
geom_line(color = "blue", size = 1) +
labs(title = "Simulated Economic Growth (Solow Growth Model)",
x = "Time Period",
y = "GDP") +
theme_minimal()
})
}
# Run the Shiny app
shinyApp(ui = ui, server = server)
Types of Shocks:
- Productivity Shock: A random shock that affects the level of productivity (e.g., technological innovation or a recession).
- Capital Shock: A random shock to the capital accumulation process (e.g., natural disasters that destroy capital).
- Labor Shock: A random shock to labor growth (e.g., demographic changes or pandemic).
We'll implement a random productivity shock in this example. Each period, the productivity will be multiplied by a random factor drawn from a normal distribution to simulate positive or negative shocks.
Example Output:
- With a low shock volatility, you will see a smooth GDP curve as the economy grows steadily.
- As you increase the shock volatility, you will notice more fluctuations and random jumps in GDP growth, simulating unpredictable events.
No comments:
Post a Comment