Function description

I provide a simplified example of a function focused on setting up and solving a basic Computable General Equilibrium (CGE) model. The function consists of the following components:

  1. Initialization and Parameterization:
  1. Equilibrium Conditions:
  1. Model Specification:
  1. Solving for the Equilibrium:
  1. Sensitivity and Policy Analysis:

The model allows for the analysis of different scenarios by changing input values or adding shocks to the parameters, such as introducing a tax policy or a subsidy. This makes it possible to see how changes in external factors affect economic outcomes, helping analyze the impact of policy changes.

Technical specification

The own developed function simulate_keynesian_model in R is designed to simulate a simple Keynesian economic model. It calculates the equilibrium level of output (income) based on several inputs, including consumption, investment, government spending, and taxes. Here’s a technical description of how the function works:

Key Components of the Function

  1. Inputs: The function accepts several parameters:
  • c0 and c1 represent the autonomous consumption and marginal propensity to consume, respectively. These define how much consumption will increase with an increase in disposable income.
  • I0 is autonomous investment, representing investment that doesn’t depend on income.
  • G stands for government spending.
  • T represents taxes.
  • iterations and tolerance set the maximum number of iterations and the acceptable tolerance level to check for equilibrium (convergence).
  1. Model Setup and Disposable Income Calculation:
  • The function initializes Y (output) and Y_old (previous output) to track income over iterations.
  • Disposable income \(Y_d\) is calculated as \(Y-T\), representing the portion of income households have after taxes.
  1. Consumption and Output Calculation:
  • Consumption (C): Calculated as \(C=c_0+c_1 \times Y_d\), where households consume a base amount (\(c_0\)) and an additional amount depending on their disposable income (\(c_1 \times Y_d\)).
  • Total Output (Y_new): Calculated as \(Y=C+I+G\), summing consumption, investment, and government spending to find total demand.
  1. Equilibrium Check (Convergence):
  • After calculating the new output level Y_new, the function checks if the difference between Y and Y_old is smaller than tolerance. If so, it assumes equilibrium is reached and stops iterating. This prevents an infinite loop and defines equilibrium as when the change in output from one iteration to the next is very small.
  1. Output Results:

When equilibrium is reached, the function returns the equilibrium values of total output (Y), consumption (C), investment (I), and government spending (G).

Example of Use

To use this function, you would set values for each input parameter, run the function, and observe the calculated equilibrium values. This simple model iteratively computes the equilibrium output level using the Keynesian framework, making it a powerful and flexible base for basic economic modeling and simulation in R.

Step 1: Define the Model

For simplicity, let’s consider above basic Keynesian model with the three main equations for output (Y), consumption (C), and investment (I):

  1. Output Equation: \(Y = C + I + G\)
  2. Consumption Function: \(C = c_0 + c_1 \cdot Y_d\)
  3. Investment Function: \(I = I_0\)
  4. Disposable Income: \(Y_d = Y - T\)

Where: - \(Y\) is the total output or income. - \(C\) is consumption. - \(I\) is investment. - \(G\) is government spending. - \(T\) is taxes. - \(c_0\) and \(c_1\) are constants for autonomous consumption and marginal propensity to consume, respectively.

Step 2: Create a Function to Simulate the Model

Here’s the sample R function that takes parameters as input and iterates to find the equilibrium level of output:

# Define the model function
simulate_keynesian_model <- function(c0, c1, I0, G, T, iterations = 100, tolerance = 1e-5) {
  # Initialize variables
  Y <- 0      # Initial guess for output
  Y_old <- -1 # For checking convergence
  
  # Iterative process to reach equilibrium
  for (i in 1:iterations) {
    # Calculate disposable income
    Y_d <- Y - T
    
    # Calculate consumption based on disposable income
    C <- c0 + c1 * Y_d
    
    # Total output (Income identity)
    Y_new <- C + I0 + G
    
    # Check for convergence
    if (abs(Y_new - Y_old) < tolerance) {
      cat("Equilibrium reached after", i, "iterations\n")
      break
    }
    
    # Update variables for next iteration
    Y_old <- Y
    Y <- Y_new
  }
  
  # Output the results
  return(list(Equilibrium_Y = Y, Consumption = C, Investment = I0, Government_Spending = G))
}

Step 3: Run the Model with Given Parameters

With this function in place, we can now simulate the model by specifying values for c0, c1, I0, G, and T. For example:

# Define parameters
c0 <- 100    # Autonomous consumption
c1 <- 0.8    # Marginal propensity to consume
I0 <- 200    # Autonomous investment
G <- 150     # Government spending
T <- 50      # Taxes

# Simulate the model
results <- simulate_keynesian_model(c0, c1, I0, G, T)
## Equilibrium reached after 84 iterations
print(results)
## $Equilibrium_Y
## [1] 2050
## 
## $Consumption
## [1] 1700
## 
## $Investment
## [1] 200
## 
## $Government_Spending
## [1] 150

Explanation

  1. Iterative Solution: The function iteratively calculates total output \(Y\) until it converges to an equilibrium, where output equals aggregate demand.
  2. Equilibrium Check: The tolerance parameter sets the convergence threshold to determine when equilibrium is reached.
  3. Outputs: The function returns a list of key values in equilibrium, including output, consumption, investment, and government spending.

Expanding the Model

To replicate more complex functions, we could expand the function by adding: - Dynamic behavior: Model dynamics over time by tracking past values of variables. - Multiple Sectors: Include equations for multiple sectors or variables, such as wages, prices, and capital accumulation. - Stochastic Shocks: Introduce random shocks to variables for stochastic simulations.

This basic function provides an example of a starting point in building and customizing our own economic models in R.