Compute the Herfindahl-Hirschman Index measuring the concentration of a country's trade across partners or products.
Details
HHI ranges from 0 (perfectly diversified) to 10,000 (single partner/product). Interpretation: < 1,500 = low concentration, 1,500-2,500 = moderate, > 2,500 = high.
Examples
# \donttest{
op <- options(comtrade.cache_dir = tempdir())
# Export partner concentration
tryCatch(ct_hhi("AUS", flow = "X", year = 2023, by = "partner"),
error = function(e) NULL)
#> Warning: Country code "ALL" not found in reference table. Passing to API as-is.
#> ℹ No API key set. Using preview endpoint (500 records max, no descriptions).
#> ℹ For full access (100k records, descriptions), get a free key at
#> <https://comtradedeveloper.un.org/>
#> ℹ Then run: `ct_set_key("your-key")`
#> NULL
# Export product concentration
tryCatch(ct_hhi("AUS", flow = "X", year = 2023, by = "product"),
error = function(e) NULL)
#> ℹ No API key set. Using preview endpoint (500 records max, no descriptions).
#> ℹ For full access (100k records, descriptions), get a free key at
#> <https://comtradedeveloper.un.org/>
#> ℹ Then run: `ct_set_key("your-key")`
#> Waiting 2s for retry backoff ■■■■■■■■■■■■■■■
#> Waiting 2s for retry backoff ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
#> NULL
options(op)
# }