Learn R Programming

GE (version 0.1.1)

sdm2: Structural Dynamic Model (alias Structural Growth Model) Version 2

Description

A new version of the sdm function in the package CGE. Now the parameter A can be a demand structure tree list. Hence we actually no longer need the function sdm_dstl. Some rarely used parameters in the function sdm have been deleted.

Usage

sdm2(
  A,
  B,
  S0Exg = matrix(NA, nrow(B), ncol(B)),
  names.commodity = paste("comm", 1:nrow(B), sep = ""),
  names.agent = paste("agt", 1:ncol(B), sep = ""),
  p0 = matrix(1, nrow = nrow(B), ncol = 1),
  z0 = matrix(100, nrow = ncol(B), ncol = 1),
  GRExg = NA,
  pExg = NULL,
  numeraire = NULL,
  tolCond = 1e-05,
  maxIteration = 200,
  numberOfPeriods = 300,
  depreciationCoef = 0.8,
  priceAdjustmentFunction = NULL,
  priceAdjustmentVelocity = 0.15,
  trace = TRUE,
  ts = FALSE,
  policy = NULL,
  exchangeFunction = F_Z
)

Arguments

A

a demand structure tree list (see demand_coefficient), a demand coefficient n-by-m matrix (alias demand structure matrix) or a function A(state) which returns an n-by-m matrix (see the sdm function).

B

a supply coefficient n-by-m matrix (alias supply structure matrix). If (i,j)-th element of S0Exg is not NA, the value of the (i,j)-th element of B will be useless and ignored.

S0Exg

an initial exogenous supply n-by-m matrix. This matrix may contain NA, but not zero.

names.commodity

names of commodities. If the parameter A is a demand structure tree list, the values in names.commodity should be the names of those leaf nodes.

names.agent

names of agents.

p0

an initial price n-vector.

z0

an m-vector consisting of the initial exchange levels (i.e. activity levels, production levels or utility levels).

GRExg

an exogenous growth rate of the exogenous supplies in S0Exg. If GRExg is NA and some commodities have exogenous supply, then GRExg will be set to 0.

pExg

an n-vector indicating the exogenous prices (if any).

numeraire

the name or index of the numeraire commodity.

tolCond

the tolerance condition.

maxIteration

the maximum iteration count. If the main purpose of running this function is to do simulation instead of calculating equilibrium, then maxIteration should be set to 1.

numberOfPeriods

the period number in each iteration.

depreciationCoef

the depreciation coefficient (i.e. 1 minus the depreciation rate) of the unsold products.

priceAdjustmentFunction

the price adjustment function. The arguments are a price n-vector p and a sales rate n-vector q. The return value is a price n-vector. The default price adjustment method is p * (1 - priceAdjustmentVelocity * (1 - q)).

priceAdjustmentVelocity

the price adjustment velocity.

trace

if TRUE, information is printed during the running of sdm.

ts

if TRUE, the time series of the last iteration are returned.

policy

a policy function. The policy function has the following optional parameters:

  • time - the current time.

  • dstl - the demand structure tree list in the model, which can be adjusted in the policy function and it need not be returned.

  • state - the current state, which is a list. state$p is the current price vector. state$S is the current supply matrix. state$last.z is the last output and utility vector. state$B is the current supply coefficient matrix.

  • state.history - the state history, which is a list consisting of the time series of p, S, q, and z.

The return value of the policy function other than a list will be ignored. If the return value is a list, it should have elements p, S and B which specify the prices, supplies and supply coefficient matrix after adjustment. A vector with the name current.policy.data can be put into the state list as well, which will be put into the return value of the sdm2.

exchangeFunction

the exchange function.

Value

A list usually containing the following components:

  • tolerance - the tolerance of the results.

  • p - equilibrium prices.

  • z- equilibrium exchange levels (i.e. activity levels, output levels or utility levels).

  • S - the equilibrium supply matrix at the initial period.

  • growthRate - the endogenous equilibrium growth rate in a pure production economy.

  • A - the equilibrium demand coefficient matrix.

  • B - the supply coefficient matrix.

  • S0Exg - the initial exogenous supply n-by-m matrix.

  • D - the demand matrix.

  • DV - the demand value matrix.

  • SV - the supply value matrix.

  • ts.p - the time series of prices in the last iteration.

  • ts.z - the time series of exchange levels (i.e. activity levels, production levels or utility levels) in the last iteration.

  • ts.S - the time series of supply matrix in the last iteration.

  • ts.q - the time series of sales rates in the last iteration.

  • policy.data - the policy data.

References

LI Wu (2019, ISBN: 9787521804225) General Equilibrium and Structural Dynamics: Perspectives of New Structural Economics. Beijing: Economic Science Press. (In Chinese)

LI Wu (2010) A Structural Growth Model and its Applications to Sraffa's System. http://www.iioa.org/conferences/18th/papers/files/104_20100729011_AStructuralGrowthModelanditsApplicationstoSraffasSstem.pdf

Examples

Run this code
# NOT RUN {
dst.firm <- node_set("output", NA,
  type = "Leontief", a = c(0.5, 1),
  "prod", "lab"
)

dst.consumer <- node_set("utility", NA, type = "Leontief", a = 1, "prod")

dstl <- list(dst.firm, dst.consumer)

B <- matrix(c(
  1, 0,
  0, 0
), 2, 2, TRUE)
S0Exg <- matrix(c(
  NA, NA,
  NA, 100
), 2, 2, TRUE)

## variable dst and technology progress
policy.TP <- function(time, state, dstl) {
  if (time >= 200) {
    dstl[[1]]$a <- c(0.5, 0.8)
  } else {
    dstl[[1]]$a <- c(0.5, 1)
  }
  state
}

ge.TP <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("prod", "lab"),
  names.agent = c("firm", "consumer"),
  policy = policy.TP,
  ts = TRUE,
  maxIteration = 1,
  numberOfPeriods = 1000
)
matplot(ge.TP$ts.z, type = "l")
plot(ge.TP$ts.p[, 1] / ge.TP$ts.p[, 2], type = "l")

## variable supply coefficient matrix and technology progress
policy.TP <- function(time, state) {
  if (time >= 200) {
    state$B[1, 1] <- 2
  } else {
    state$B[1, 1] <- 1
  }
  state
}

ge.TP <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("prod", "lab"),
  names.agent = c("firm", "consumer"),
  policy = policy.TP,
  ts = TRUE,
  maxIteration = 1,
  numberOfPeriods = 1000
)
matplot(ge.TP$ts.z, type = "l")
plot(ge.TP$ts.p[, 1] / ge.TP$ts.p[, 2], type = "l")

## variable dst and disequilibrium
policy.DE <- function(time, dstl) {
  if (time >= 200) {
    dstl[[1]]$a[2] <- dstl[[1]]$a[2] * 0.999
  } else {
    dstl[[1]]$a[2] <- 1
  }
}

ge.DE <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("prod", "lab"),
  names.agent = c("firm", "consumer"),
  policy = policy.DE,
  ts = TRUE,
  maxIteration = 1,
  numberOfPeriods = 1000
)
matplot(ge.DE$ts.z, type = "l")
plot(ge.DE$ts.p[, 1] / ge.DE$ts.p[, 2], type = "l")


## structural equilibria and structural transition
policy.SE <- function(time, state, dstl) {
  dstl[[1]]$a[2] <- structural_function(state$last.z[1], c(105, 125), 1, 0.5)
}

ge.low.level <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("prod", "lab"),
  names.agent = c("firm", "consumer"),
  policy = policy.SE,
  ts = TRUE,
  maxIteration = 1,
  numberOfPeriods = 1000,
  z0 = c(100, 100)
)
matplot(ge.low.level$ts.z, type = "l")

ge.high.level <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("prod", "lab"),
  names.agent = c("firm", "consumer"),
  policy = policy.SE,
  ts = TRUE,
  maxIteration = 1,
  numberOfPeriods = 1000,
  z0 = c(150, 100)
)
matplot(ge.high.level$ts.z, type = "l")

policy.ST <- function(time, state, dstl) {
  dstl[[1]]$a[2] <- structural_function(state$last.z[1], c(105, 125), 1, 0.5)
  if (time >= 200 && time <= 210) state$S[2, 2] <- 125 # Introduce foreign labor.
  state
}

ge.ST <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("prod", "lab"),
  names.agent = c("firm", "consumer"),
  policy = policy.ST,
  ts = TRUE,
  maxIteration = 1,
  numberOfPeriods = 1000,
  z0 = c(100, 100)
)
matplot(ge.ST$ts.z, type = "l")

#### economic cycles and an interest rate policy for the firm
dst.firm <- node_set("agent", NA,
  type = "FIN",
  rate = c(1, 0.25),
  "cc1", "money"
)
node_set(dst.firm, "cc1",
  type = "Leontief",
  a = c(0.5, 0.5),
  "wheat", "labor"
)

dst.laborer <- Clone(dst.firm)
dst.money.lender <- Clone(dst.firm)

dstl <- list(dst.firm, dst.laborer, dst.money.lender)

policy.interest.rate <- function(time, state, dstl, state.history) {
  upsilon <- NA
  if (time >= 600) {
    upsilon <- state.history$z[time - 1, 1] / mean(state.history$z[(time - 50):(time - 1), 1])
    dstl[[1]]$rate[2] <- max(0.25 + 0.5 * log(upsilon), 0)
  } else {
    dstl[[1]]$rate[2] <- 0.25
  }

  state$current.policy.data <- c(time, dstl[[1]]$rate[2], upsilon)
  state
}

B <- matrix(0, 3, 3)
B[1, 1] <- 1

S0Exg <- matrix(NA, 3, 3)
S0Exg[2, 2] <- 100
S0Exg[3, 3] <- 100

de <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("wheat", "labor", "money"),
  names.agent = c("firm", "laborer", "money.lender"),
  p0 = rbind(0.625, 0.375, 0.25),
  z0 = rbind(95, 100, 100),
  priceAdjustmentVelocity = 0.3,
  numberOfPeriods = 1000,
  maxIteration = 1,
  trace = FALSE,
  ts = TRUE
)
matplot(de$ts.z, type = "l")

ge.policy <- sdm2(
  A = dstl, B = B, S0Exg = S0Exg,
  names.commodity = c("wheat", "labor", "money"),
  names.agent = c("firm", "laborer", "money.lender"),
  p0 = rbind(0.625, 0.375, 0.25),
  z0 = rbind(95, 100, 100),
  priceAdjustmentVelocity = 0.3,
  numberOfPeriods = 1000,
  maxIteration = 1,
  trace = FALSE,
  ts = TRUE,
  policy = policy.interest.rate
)
matplot(ge.policy$ts.z, type = "l")

#### Example 9.3 in Li (2019): fixed-ratio price adjustment method
#### and disequilibrium (business cycles) in a pure production economy
fixedRatioPriceAdjustmentFunction <- function(p, q) {
  thresholdForPriceAdjustment <- 0.99
  priceAdjustmentVelocity <- 0.02
  result <- ifelse(q <= thresholdForPriceAdjustment,
    p * (1 - priceAdjustmentVelocity),
    p
  )
  return(prop.table(result))
}

de.Sraffa <- sdm2(
  A = matrix(c(
    56 / 115, 6,
    12 / 575, 2 / 5
  ), 2, 2, TRUE),
  B = diag(2),
  maxIteration = 1,
  numberOfPeriods = 100,
  p0 = rbind(1 / 15, 1),
  z0 = rbind(575, 20),
  priceAdjustmentFunction = fixedRatioPriceAdjustmentFunction,
  ts = TRUE
)
matplot(growth_rate(de.Sraffa$ts.z), type = "l")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab