convert_to_net_trade: Converts data to net trade data

View source: R/cleans.R

convert_to_net_tradeR Documentation

Converts data to net trade data

Description

This function enables to convert a .tidy_iea_df to a new .tidy_iea_df in which trade flows are reported as net flows. So, if a given region or country both imports and exports a given product, the function will report only the difference between imports and exports, depending on which flow is dominant. See Details for uses.

Usage

convert_to_net_trade(
  .tidy_iea_df,
  imports = IEATools::interface_industries$imports,
  exports = IEATools::interface_industries$exports,
  country = IEATools::iea_cols$country,
  e_dot = IEATools::iea_cols$e_dot,
  flow = IEATools::iea_cols$flow,
  year = IEATools::iea_cols$year,
  ledger_side = IEATools::iea_cols$ledger_side,
  flow_aggregation_point = IEATools::iea_cols$flow_aggregation_point,
  product = IEATools::iea_cols$product,
  .net_imports = "Net_Imports"
)

Arguments

.tidy_iea_df

The .tidy_iea_df which trade flows need to be converted to net trade flows.

imports

The name of the Imports flows in the .tidy_iea_df. Default is IEATools::interface_industries$imports.

exports

The name of the Exports flows in the .tidy_iea_df. Default is IEATools::interface_industries$exports.

country, e_dot, flow, year, ledger_side, flow_aggregation_point, product

See IEATools::iea_cols.

.net_imports

A temporary column that calculates net imports as the difference between imports and exports. Default is "Net_Imports".

Details

The function may be use after aggregating regions with the IEATools::aggregate_regions() function, or may be applied to IEA data for aggregated regions (such as World) for which both imports and exports are reported for a given product.

Value

A .tidy_iea_df for which trade flows are converted to net trade.

Examples

# In this example, we gather all flows for countries A and B
# in a new "AB" region, for which both imports and exports are reported for some products.
tidy_AB_data %>%
dplyr::mutate(Country = "AB") %>%
dplyr::filter(stringr::str_detect(Flow, "Imports") | stringr::str_detect(Flow, "Exports")) %>%
print()
# After running the function, only either imports or exports are reported for each product.
tidy_AB_data %>%
dplyr::mutate(Country = "AB") %>%
convert_to_net_trade() %>%
dplyr::filter(stringr::str_detect(Flow, "Imports") | stringr::str_detect(Flow, "Exports")) %>%
print()

earamendia/ECCTools documentation built on May 12, 2023, 2:12 a.m.