10  Custom shocks

10.1 Overview

ems_custom_shock() allows for heterogeneous shocks specified on a tuple-by-tuple basis, supplied as a data frame or CSV file through input. Values are denominated in percentage change. Only the tuples present in input are shocked.

ems_custom_shock(var, input)
Argument Type Description
var Character Variable name as it appears in the model file
input Data frame or Character Data frame or path to a CSV file containing set columns and a Value column (percentage changes)

10.2 Full variable custom shocks

Custom shocks can be carried out over the full variable, with every tuple receiving a specified shock value. Here is a demonstration of 4 custom shocks carried out on all variable tuples for a range of variable dimensions with the GTAP-INT model.

Elements for data frame construction

time_steps <- c(0, 1, 2, 3)
REG <- c("chn", "usa", "row")
ENDW_COMM <- c("labor", "capital", "natlres", "land")
TRAD_COMM <- c("svces", "food", "crops", "mnfcs", "livestock")
PROD_COMM <- c("svces", "food", "crops", "mnfcs", "livestock", "zcgds")
MARG_COMM <- "svces"
ALLTIME <- seq(0, length(time_steps) - 1)

2D data frame and shock

pop <- expand.grid(
  REGr = REG,
  ALLTIMEt = ALLTIME,
  stringsAsFactors = FALSE
)

pop <- pop[do.call(order, pop), ]
pop$Value <- runif(nrow(pop))

pop_shk <- ems_custom_shock(
  var = "pop",
  input = pop
)

3D data frame and shock

aoall <- expand.grid(
  PROD_COMMj = PROD_COMM,
  REGr = REG,
  ALLTIMEt = ALLTIME,
  stringsAsFactors = FALSE
)

aoall <- aoall[do.call(order, aoall), ]
aoall$Value <- runif(nrow(aoall))

aoall_shk <- ems_custom_shock(
  var = "aoall",
  input = aoall
)

4D data frame and shock

afeall <- expand.grid(
  ENDW_COMMi = ENDW_COMM,
  PROD_COMMj = PROD_COMM,
  REGr = REG,
  ALLTIMEt = ALLTIME,
  stringsAsFactors = FALSE
)

afeall <- afeall[do.call(order, afeall), ]
afeall$Value <- runif(nrow(afeall))

afeall_shk <- ems_custom_shock(
  var = "afeall",
  input = afeall
)

5D data frame and shock

atall <- expand.grid(
  MARG_COMMm = MARG_COMM,
  TRAD_COMMi = TRAD_COMM,
  REGr = REG,
  REGs = REG,
  ALLTIMEt = ALLTIME,
  stringsAsFactors = FALSE
)

atall <- atall[do.call(order, atall), ]
atall$Value <- runif(nrow(atall))

atall_shk <- ems_custom_shock(
  var = "atall",
  input = atall
)

Multiple custom shocks are combined in a list for ems_deploy():

cmf_path <- ems_deploy(
  .data = .data,
  model = model,
  shock = list(pop_shk, aoall_shk, afeall_shk, atall_shk)
)

Custom shocks can also be loaded from CSV files by passing a file path to "input" instead of a data frame.

10.3 Partial variable custom shocks

Custom shocks are only carried out on tuples included within the input data frame or CSV. Here we carry out a custom shock (heterogenous values) across part of the aoall variable. The non-shocked values will remain at 0 due to their exogenous status.

aoall_full <- expand.grid(
  PROD_COMMj = PROD_COMM,
  REGr = REG,
  ALLTIMEt = ALLTIME,
  stringsAsFactors = FALSE
)
aoall_full$Value <- 0
aoall_full <- aoall_full[do.call(order, aoall_full), ]

aoall <- aoall_full[aoall_full$PROD_COMMj == "crops" & aoall_full$REGr == "chn", ]
aoall$Value <- runif(nrow(aoall))

aoall_shk <- ems_custom_shock(var = "aoall", input = aoall)