convert_to_net_trade.Rd
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.
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"
)
The .tidy_iea_df
which trade flows need to be converted to net trade flows.
The name of the Imports flows in the .tidy_iea_df
.
Default is IEATools::interface_industries$imports
.
The name of the Exports flows in the .tidy_iea_df
.
Default is IEATools::interface_industries$exports
.
See IEATools::iea_cols
.
A temporary column that calculates net imports as the difference between imports and exports. Default is "Net_Imports".
A .tidy_iea_df
for which trade flows are converted to net trade.
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.
# 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()
#> # A tibble: 8 × 11
#> Country Method Energy.type Last.stage Year Ledger.side Flow.aggregation.point
#> <chr> <chr> <chr> <chr> <dbl> <chr> <chr>
#> 1 AB PCM E Final 2018 Supply Total primary energy …
#> 2 AB PCM E Final 2018 Supply Total primary energy …
#> 3 AB PCM E Final 2018 Supply Total primary energy …
#> 4 AB PCM E Final 2018 Supply Total primary energy …
#> 5 AB PCM E Final 2018 Supply Total primary energy …
#> 6 AB PCM E Final 2018 Supply Total primary energy …
#> 7 AB PCM E Final 2018 Supply Total primary energy …
#> 8 AB PCM E Final 2018 Supply Total primary energy …
#> # ℹ 4 more variables: Flow <chr>, Product <chr>, Unit <chr>, E.dot <dbl>
# 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()
#> # A tibble: 2 × 11
#> Country Method Energy.type Last.stage Year Ledger.side Flow.aggregation.point
#> <chr> <chr> <chr> <chr> <dbl> <chr> <chr>
#> 1 AB PCM E Final 2018 Supply Total primary energy …
#> 2 AB PCM E Final 2018 Supply Total primary energy …
#> # ℹ 4 more variables: Flow <chr>, Product <chr>, Unit <chr>, E.dot <dbl>