| shock_calculate | R Documentation |
Computes compounded GEMPACK-style percentage shocks between initial and target values, producing multi-period shock series for dynamic simulation models. The function automatically aligns dimensions across datasets and exports results in HAR format.
shock_calculate(
initial_config,
target_config,
calc_config,
output_path,
long_desc = "Calculated shock values",
dim_order = NULL,
lowercase = FALSE
)
initial_config |
A list created by
|
target_config |
A list created by
|
calc_config |
A list created by
|
output_path |
Path to the output HAR file where calculated shocks will be written. |
long_desc |
Optional text for header description. Default is "Calculated shock values". |
dim_order |
Optional dimension ordering specification. Can be:
|
lowercase |
Logical; if TRUE, converts dimension elements to lowercase. Default is FALSE. |
Computes percentage shocks using compounded "power of tax" formula
Supports multiple periods defined via timeline configuration
Compatible with HAR, SL4, CSV, or XLSX input formats
Excludes self-trade or specified region-sector pairs when configured
Exports results as multi-header HAR file (one header per timeline period)
Invisibly returns a list containing summary metadata:
n_observations: total records processed
n_included: records included in shock computation
n_excluded: records excluded by configuration
output_path: normalized path to output HAR file
Pattawee Puangchit
shock_calculate_uniform, create_initial_config,
create_target_config, create_calc_config, save_har
# Example 1: Target-Based Shock Calculation
har_path <- system.file("extdata", "baserate.har", package = "HARplus")
# Sorting Column
mapping <- list(
REG = c("USA", "EU", "ROW")
)
# Initial File
initial <- create_initial_config(
path = har_path,
format = "har",
header = "rTMS"
)
# Target File
target <- create_target_config(
path = har_path,
type = "har",
header = "rTMS"
)
# Calculation Setup with Column Mapping
calc <- create_calc_config(
column_mapping = c(TRAD_COMM = "TRAD_COMM", REG = "REG", REG.1 = "REG.1"),
timeline = "1-5",
exclude_self_trade = TRUE
)
# Compute Shock Based on Initial and Target Values
shock_calculate(
initial_config = initial,
target_config = target,
calc_config = calc,
output_path = file.path(tempdir(), "output_target.har"),
dim_order = mapping
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.