Learn R Programming

HARplus (version 1.1.2)

shock_calculate_uniform: Calculate Shocks with Uniform Adjustment

Description

Generates GEMPACK-style percentage shocks using a uniform proportional adjustment applied to all values in the initial dataset. The function supports additive or multiplicative adjustments, single or multi-period configurations, and direct HAR export.

Usage

shock_calculate_uniform(
  initial_config,
  adjustment_value,
  calculation_method = "*",
  calc_config,
  output_path,
  long_desc = "Uniform shock adjustment",
  dim_order = NULL,
  lowercase = FALSE
)

Value

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 the generated HAR file

Arguments

initial_config

A list created by create_initial_config, defining:

  • Input file path, format, and variable header

  • Column name for initial rate values ("Value_ini")

adjustment_value

Numeric scalar specifying the uniform adjustment to apply.

  • Interpreted according to calculation_method

  • For example, 0.5 with method "*" halves the base rate

calculation_method

Operator defining the adjustment method:

  • "*" multiply (default)

  • "/" divide

  • "+" add

  • "-" subtract

calc_config

A list created by create_calc_config, specifying:

  • timeline: sequence of simulation periods (e.g., "1-10")

  • exclude_self_trade: logical, whether to omit intra-region pairs

  • exclusion_values: optional list defining excluded elements

output_path

Path to the output HAR file where calculated shocks will be written.

long_desc

Optional text for header description. Default is "Uniform shock adjustment".

dim_order

Optional dimension ordering specification. Can be:

  • NULL (default): alphabetical A-Z ordering

  • a named list defining preferred order per dimension

  • a data frame or path to Excel/CSV with explicit order definitions

lowercase

Logical; if TRUE, converts all dimension elements to lowercase. Default is FALSE.

Author

Pattawee Puangchit

Details

  • Applies uniform adjustment to all base rates across defined dimensions

  • Supports additive ("+", "-") and proportional ("*", "/") adjustments

  • Computes compounded shocks following the "power of tax" formulation

  • Handles multiple time periods as defined by timeline in calc_config

  • Excludes self-trade or specified region/sector pairs if configured

  • Outputs results as multi-header HAR file (one per timeline period)

See Also

shock_calculate, create_initial_config, create_calc_config, save_har

Examples

Run this code
# Example 1: Uniform Shock (50% Reduction)
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"
)

# Calculation Setup
calc <- create_calc_config(
  timeline           = "1-10",
  exclude_self_trade = TRUE
)

# Compute Uniform 50% Reduction (Value_tar = Value_ini * 0.5)
shock_calculate_uniform(
  initial_config     = initial,
  adjustment_value   = 0.5,
  calculation_method = "*",
  calc_config        = calc,
  output_path        = file.path(tempdir(), "output_uniform.har"),
  dim_order          = mapping
)

Run the code above in your browser using DataLab