The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Trade Intensity, Openness and Diversification with tradeIndices

Chiranjit Mazumder and Renjini V. R.

Overview

tradeIndices calculates frequently used international trade indicators from numeric vectors. It deliberately separates measurement from data acquisition, allowing researchers to use UN Comtrade, World Bank, national, or independently verified data.

library(tradeIndices)

The numerical data below are illustrative agricultural-trade values and should not be interpreted as official statistics.

Trade openness

Trade openness is exports plus imports divided by GDP:

\[ TO_t = 100\frac{X_t+M_t}{GDP_t}. \]

macro <- data.frame(
  year = 2020:2024,
  exports = c(276, 302, 326, 351, 379),
  imports = c(365, 421, 457, 493, 528),
  gdp = c(2667, 3150, 3390, 3570, 3810)
)

macro$openness <- with(
  macro,
  trade_openness(exports, imports, gdp)
)
macro
#>   year exports imports  gdp openness
#> 1 2020     276     365 2667 24.03450
#> 2 2021     302     421 3150 22.95238
#> 3 2022     326     457 3390 23.09735
#> 4 2023     351     493 3570 23.64146
#> 5 2024     379     528 3810 23.80577
plot(
  macro$year, macro$openness,
  type = "o", pch = 16, lwd = 2, col = "#1B5E20",
  xlab = "Year", ylab = "Trade openness (% of GDP)",
  main = "Illustrative trade-openness series"
)
grid()

The monetary units cancel, but exports, imports, and GDP must be expressed in the same unit and price basis.

Bilateral trade intensity

For reporter country \(i\) and partner \(j\), conventional export intensity is

\[ TII_{ij}=\frac{X_{ij}/X_i}{M_j/M_w}. \]

intensity <- data.frame(
  year = 2020:2024,
  bilateral_exports = c(14, 16, 19, 21, 25),
  reporter_exports = c(180, 195, 210, 225, 245),
  world_exports_to_partner = c(310, 335, 360, 390, 420),
  world_exports = c(4300, 4650, 4920, 5180, 5490)
)

intensity$tii <- with(
  intensity,
  trade_intensity(
    bilateral_exports,
    reporter_exports,
    world_exports_to_partner,
    world_exports
  )
)
intensity
#>   year bilateral_exports reporter_exports world_exports_to_partner
#> 1 2020                14              180                      310
#> 2 2021                16              195                      335
#> 3 2022                19              210                      360
#> 4 2023                21              225                      390
#> 5 2024                25              245                      420
#>   world_exports      tii
#> 1          4300 1.078853
#> 2          4650 1.138921
#> 3          4920 1.236508
#> 4          5180 1.239658
#> 5          5490 1.333819

Values above one indicate that the reporter directs a larger export share to the partner than the partner represents in world imports. This is a relative measure and is not the value or growth rate of bilateral trade.

Concentration and evenness-based diversification

products <- c(rice = 45, wheat = 25, tea = 20, spices = 10)

c(
  HHI = trade_concentration(products),
  HHI_10000 = trade_concentration(products, scale = 10000),
  One_minus_HHI = trade_diversification(products),
  Normalized_HHI_diversity = trade_diversification(
    products, method = "normalized_hhi"
  ),
  Shannon = trade_diversification(products, method = "shannon"),
  Effective_products = trade_diversification(
    products, method = "effective_number"
  )
)
#>                      HHI                HHI_10000            One_minus_HHI 
#>                0.3150000             3150.0000000                0.6850000 
#> Normalized_HHI_diversity                  Shannon       Effective_products 
#>                0.9133333                0.9074899                3.5185471

Higher HHI means concentration. Higher one-minus-HHI, normalized HHI diversity, and normalized Shannon entropy mean a more even distribution. The effective number converts entropy into the number of equally important categories that would generate the same entropy.

When indices are compared over time or across countries, the product classification and included category universe should remain consistent.

The package includes a small illustrative agricultural-trade file for reproducible practice:

example_file <- system.file(
  "extdata", "agricultural_trade_example.csv",
  package = "tradeIndices"
)
ag_trade <- read.csv(example_file)

diversity_by_year <- vapply(
  split(ag_trade$country_exports, ag_trade$year),
  trade_diversification,
  numeric(1),
  method = "normalized_hhi"
)

plot(
  as.integer(names(diversity_by_year)), diversity_by_year,
  type = "o", pch = 16, lwd = 2, col = "#8D6E63",
  xlab = "Year", ylab = "Normalized HHI diversification",
  main = "Illustrative agricultural export diversification"
)
grid()

Structural diversification relative to a benchmark

The structural diversification index compares a country’s product shares with a benchmark such as world exports:

\[ DIV_i=\frac{1}{2}\sum_k\left|s_{ik}-s_{wk}\right|. \]

country_exports <- c(rice = 45, wheat = 25, tea = 20, spices = 10)
world_exports <- c(spices = 30, tea = 15, wheat = 35, rice = 20)

c(
  Structural_distance = trade_diversification_index(
    country_exports, world_exports
  ),
  Export_similarity = export_similarity(
    country_exports, world_exports
  )
)
#> Structural_distance   Export_similarity 
#>                 0.3                70.0

Named vectors are automatically aligned by category. A high structural index means that the country’s export pattern differs from the benchmark. It does not necessarily mean that the country’s export basket is more evenly diversified; use trade_diversification() for that question.

Additional indicators

rca_balassa(
  country_product_exports = c(rice = 40, wheat = 20, tea = 10),
  country_total_exports = 100,
  world_product_exports = c(rice = 300, wheat = 500, tea = 200),
  world_total_exports = 5000
)
#> [1] 6.666667 2.000000 2.500000

grubel_lloyd(
  exports = c(rice = 40, wheat = 25, tea = 30),
  imports = c(rice = 10, wheat = 20, tea = 28),
  aggregate = TRUE
)
#> [1] 75.81699

Balassa RCA above one indicates that a product’s export share is higher in the country than in the world benchmark. A high Grubel-Lloyd value indicates a larger share of two-way, within-product trade.

Reproducible workflow

For a country-year panel:

  1. Use the same monetary units within every formula.
  2. Keep commodity classifications consistent across years.
  3. Retain zero-trade categories when comparing normalized diversification.
  4. Document whether conventional or reporter-excluded intensity is used.
  5. Treat mirrored bilateral flows and reported flows as different data series; do not combine them without reconciliation.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.