transform_to_gma.Rmd
In this vignette we explain how the Global Market Assumption can be formulated from a .tidy_iea_df
.
The Global Market Assumption assumes a global market for each traded product. For each product \(p\), the exporting share of each exporting country \(s\) is determined as (see Aramendia et al. (2022)):
\[c_{s,p} = \frac{x_{s,p}}{x_p}\]
where:
We note that:
\[\sum_{s \in \mathcal{S}} c_{s,p} = 1\]
where \(\mathcal{S}\) stands for the set of countries considered.
Hence, each country importing a product \(p\) will import the share \(c_{s,p}\) of its imports of product \(p\) from country \(s\).
The Global Market Assumption is therefore a simplifying assumption which enables to:
To formulate the Global Market Assumption, one simply needs to:
IEATools::add_psut_matnames')
to add a matrix name column.convert_to_net_trade()
, which converts trade data to net trade. See “Possible issues” below.transform_to_gma()
function.Let’s see the example with the AB world example:
tidy_AB_data_gma <- tidy_AB_data %>%
IEATools::add_psut_matnames() %>%
convert_to_net_trade() %>%
transform_to_gma() %>%
dplyr::glimpse()
## Rows: 101
## Columns: 12
## $ Country <chr> "World", "World", "World", "World", "World", "W…
## $ Method <chr> "PCM", "PCM", "PCM", "PCM", "PCM", "PCM", "PCM"…
## $ Energy.type <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "E…
## $ Last.stage <chr> "Final", "Final", "Final", "Final", "Final", "F…
## $ Year <dbl> 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,…
## $ Ledger.side <chr> "Supply", "Supply", "Supply", "Supply", "Supply…
## $ Flow.aggregation.point <chr> "Total primary energy supply", "Total primary e…
## $ Flow <chr> "{A}_Resources [of Coking coal]", "{A}_Resource…
## $ Product <chr> "{A}_Coking coal [from Resources]", "{A}_Crude …
## $ Unit <chr> "ktoe", "ktoe", "ktoe", "ktoe", "ktoe", "ktoe",…
## $ E.dot <dbl> 5000, 8500, 4000, 600, 2000, 3000, 2500, 850, 5…
## $ matnames <chr> "R", "R", "R", "R", "R", "R", "R", "V", "V", "V…
The locations of each flow is now noted with the prefix "{Country}_" in the “Flow” column, and so is the location of origin of a given product in the “Product” column.
Here we can see that unbalances appear. Indeed, that is due to the fact that imports and exports do not balance for some products (coke oven coke, crude oil).
tidy_AB_data_gma %>%
IEATools::calc_tidy_iea_df_balances() %>%
IEATools::tidy_iea_df_balanced()
## [1] FALSE
To solve this issue, we can add a balancing vector to the B matrix. This is an approximate fix and should be handled carefully, it is only valid in the cases where the unbalances appearing is negligible compared to most energy flows. The balancing vector can be used to estimate the uncertainty of results.
tidy_AB_data_gma %>%
add_balancing_vector() %>%
IEATools::calc_tidy_iea_df_balances() %>%
IEATools::tidy_iea_df_balanced()
## [1] TRUE
Two possible issues are worth noting here; first, the issue of an imported product not being produced anywhere, and second, the issue of a country both importing and exporting a given product. We note that these issues will also cause issues when applying the Bilateral Trade Assumption, and hence should be avoided prior to running either the transform_to_gma()
or the transform_to_bta()
function.
A potential inconsistency in IEA data is the case of a country importing a product \(p\) which is not produced anywhere else. Let us show an example with the AB world. Say that country B also imports “A very odd product,” but that country A does not produce it (and hence, doesn’t export it).
tidy_AB_data %>%
# Country B consumes "a very odd product" in its "very odd industry
tibble::add_row(Country = "B", Method = "PCM", Energy.type = "E", Last.stage = "Final", Year = 2018,
Ledger.side = "Consumption", Flow.aggregation.point = "Industry",
Flow = "Very odd industry", Product = "A very odd product", Unit = "ktoe", E.dot = 100) %>%
# Country B imports "a very odd product" from somewhere
tibble::add_row(Country = "B", Method = "PCM", Energy.type = "E", Last.stage = "Final", Year = 2018,
Ledger.side = "Supply", Flow.aggregation.point = "Total primary energy supply",
Flow = "Imports [of A very odd product]", Product = "A very odd product", Unit = "ktoe", E.dot = 100) %>%
IEATools::add_psut_matnames() %>%
convert_to_net_trade() %>%
transform_to_gma() %>%
dplyr::glimpse()
## Error: There an NA in the join here, do worry about it.
As expected, the code above returns an error.
Note: In the case where a product \(p\) is imported by a given country but (1) is not exported by any other country, and (2) is produced by some other countries, we determine and apply the global production shares, instead of exports shares. This is an approximate way to deal with IEA data inconsistencies.
The transform_to_gma()
function is not able to deal properly with a region that both imports and exports a given product. In other words, the data provided as input to the function needs to be described in net trade terms: either a product is imported, or is exported, by a given region.
The case of having a region that both imports and exports a given product may however happen for two reasons:
To run the transform_to_gma()
function, one can use the convert_to_net_trade()
function, which will calculate the difference between imported and exported products, and report traded products either as imports or as exports, depending on whether there are more imports than exports of product \(p\) or not.