International trade constitutes a central pillar in the architecture of contemporary economies, exerting significant influence over their structural composition and macroeconomic dynamics. This report provides a comprehensive analysis of trade and economic interrelations, focusing on critical indicators such as trade dependence, import penetration, export propensity, and the marginal propensity to import. These metrics serve as proxies for assessing the openness, structural sensitivity, and external orientation of an economy vis-à-vis global markets.

The assessment further incorporates trade performance indicators—including the growth rates of exports and imports, the normalized trade balance, and the export-import coverage ratio—which collectively offer insights into the external competitiveness, sustainability of the trade position, and the evolving trade dynamics of the economy under study.

In addition, the direction of trade is analyzed through measures such as trade intensity indices, intra-regional trade shares, and trade entropy. These indicators facilitate the examination of trade partner concentration, regional integration levels, and the diversification of trade flows. Together, these analytical dimensions form an integrated framework to evaluate trade behavior, structural dependencies, and strategic trade alignments within the broader context of international economic relations.

Packages:

library(tidyverse)
library(readxl)
library(WDI)
options(scipen = 100)

Trade and Economy.

The relationship between trade and economic structure is captured through indicators that measure a country’s integration into global markets. Trade dependence reflects the relative weight of external trade in GDP, while import penetration indicates the extent to which domestic demand is satisfied by foreign goods. Export propensity gauges the share of domestic production directed toward foreign markets, and the marginal propensity to import highlights how additional income translates into increased import demand. Together, these variables reveal the degree of openness, structural exposure, and responsiveness of an economy to international trade flows.

TradeData <- read_excel("~/R/Comercio/TradeData.xlsx")
TradeData <- TradeData %>% 
  select(refYear, reporterDesc, flowDesc, partnerDesc, primaryValue)
TradeData <- TradeData %>% 
  rename(year = refYear, reporter = reporterDesc, trade_direction = flowDesc, 
         partner = partnerDesc, trade_value_usd = primaryValue)
TradeData
## # A tibble: 3,872 × 5
##     year reporter    trade_direction partner trade_value_usd
##    <dbl> <chr>       <chr>           <chr>             <dbl>
##  1  2013 Afghanistan Import          World       8554413749 
##  2  2013 Afghanistan Export          World        514972983 
##  3  2013 Albania     Import          World       4880593254 
##  4  2013 Albania     Export          World       2331521928 
##  5  2013 Algeria     Import          World      54909973274 
##  6  2013 Algeria     Export          World      65998137595 
##  7  2013 Andorra     Import          World       1487194094.
##  8  2013 Andorra     Export          World         98990694.
##  9  2013 Angola      Import          World      26756062991 
## 10  2013 Angola      Export          World      67712526547 
## # ℹ 3,862 more rows

Trade Dependence Index.

The trade dependence index (also often called the openness index) is a measure of the importance of international trade in the overall economy. It can give an indication of the degree to which an economy is open to trade (subject to some serious limitations).

Definition: The value of total trade (imports plus exports) as a percentage of GDP.

Mathematical definition: \(TDI=\frac{\sum_{s}X_{ds}+\sum_{s}M_{sd}}{GDP_d}100\)

where d is the country under study, s is the set of all other countries, X is total bilateral exports, M is total bilateral imports and GDP is gross domestic product (of country d). In words, the numerator is total exports from d plus total imports to d, and the denominator is the GDP of d.

Limitations: Openness of an economy is determined by a large number of factors, most importantly by trade restrictions like tariffs, non-tariff barriers, foreign exchange regimes, non-trade policies and the structure of national economies. The share of trade transactions in a country’s value added is a result of all these factors. It is possible that an open and liberalized economy has a relatively small TDI, if a large proportion of its GDP is created by non-traded activities supported by the domestic market. Low trade dependence may indicate high trade restrictions either in that country or toward that country in the overseas markets, or both.

Let’s calculate the TDI for Spain in the time period from 2016 through to 2020.

TDI <- TradeData %>% 
  filter(reporter == "Spain") %>% 
  select(year, trade_direction, trade_value_usd)
TDI <- spread(TDI, trade_direction, trade_value_usd)
gdp <- WDI(indicator= c("GDP" = "NY.GDP.MKTP.CD"), country="ESP", start=2018, end=2024)
TDI <- merge(TDI, gdp, by = "year") %>% select(year, Export, Import, GDP)
TDI
##   year       Export       Import           GDP
## 1 2018 346064315051 391056705310 1431642809327
## 2 2019 337202601408 375470067282 1403496387686
## 3 2020 312080513421 329738801366 1289783836971
## 4 2021 391558519477 426059816727 1461244901853
## 5 2022 424286054810 499055069367 1446498147749
## 6 2023 420169591003 469043091352 1620090734957
## 7 2024 403702939156 451303134203            NA

We can now calculate the Trade Dependence Index by following the operations shown in the formula and store the results into a new variable named tdi. Finally, we round the TDI value to have a clearer view of the result.

TDI$tdi <- (TDI$Export + TDI$Import)/TDI$GDP*100 
TDI <- TDI %>% select(year, tdi)
TDI$tdi <- round(TDI$tdi, 0)
TDI
##   year tdi
## 1 2018  51
## 2 2019  51
## 3 2020  50
## 4 2021  56
## 5 2022  64
## 6 2023  55
## 7 2024  NA

Now let’s calculate TDI for a set of 27 economies - European Union - in 2020, and display the result in a bar plot. Again, we use spread() to separate Import and Export data into separate columns.

EU.27 <- c("Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czechia", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden")
x <- TradeData %>% 
  filter(reporter %in% EU.27 & year == 2020) %>% 
  select(reporter, trade_direction, trade_value_usd)
x <- spread(x, trade_direction, trade_value_usd)

gdp <- WDI(indicator= c("GDP" = "NY.GDP.MKTP.CD"), 
           country= c("AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "IRL", "ITA", "LVA", "LTU", "LUX", "MLT", "NLD", "POL", "PRT", "ROU", "SVK", "SVN", "ESP", "SWE" ), start=2020, end=2020)
gdp$country[gdp$country=="Slovak Republic"] <- "Slovakia" # rename Slovakia to ensure consistency
x <- merge(x, gdp, by.x = "reporter", by.y = "country") %>% 
  select(reporter, Export, Import, GDP)
x
##       reporter        Export        Import           GDP
## 1      Austria  162145129017  164635579304  434397601558
## 2      Belgium  295143761844  294246686005  529694473502
## 3     Bulgaria   31914703883   35027243633   70716821235
## 4      Croatia   16991280298   26095988209   57963370885
## 5       Cyprus    3137095808    8728558941   25555093854
## 6      Czechia  192307379805  171440208263  251109660603
## 7      Denmark  106871154269   95778398379  355631021932
## 8      Estonia   16901599064   17764140293   31820771494
## 9      Finland   65606975840   68266522010  270000311606
## 10      France  487987460595  580805912500 2647926055110
## 11     Germany 1385852259832 1173167331768 3940142541354
## 12      Greece   35070461606   55533637799  191362985555
## 13     Hungary  119970720482  113422659451  157288955508
## 14     Ireland  185185364985   99441600379  436555518400
## 15       Italy  498803831971  426475840329 1907481094079
## 16      Latvia   15196527244   17315082294   33379927435
## 17   Lithuania   32790372365   33313760619   57412038533
## 18  Luxembourg   13506053446   20882683235   73699366700
## 19       Malta    2831908163    5736087959   16385919536
## 20 Netherlands  551352792282  484088530593  932560861701
## 21      Poland  254169031902  254660433330  605914237904
## 22    Portugal   61400262161   77834419564  229618773423
## 23     Romania   71046398784   92056306062  252033792712
## 24    Slovakia   86707796106   84998491747  107732602896
## 25    Slovenia   37471094173   36512669081   53384760135
## 26       Spain  312080513421  329738801366 1289783836971
## 27      Sweden  154935587126  149436257459  545147614972

As was previously done, we calculate TDI for all countries and store the values into tdi column. Let’s round the calculated values to zero decimals.

x$tdi <- (x$Export + x$Import)/x$GDP*100
x$tdi <- round(x$tdi, 0)
x[, c("reporter", "tdi")]
##       reporter tdi
## 1      Austria  75
## 2      Belgium 111
## 3     Bulgaria  95
## 4      Croatia  74
## 5       Cyprus  46
## 6      Czechia 145
## 7      Denmark  57
## 8      Estonia 109
## 9      Finland  50
## 10      France  40
## 11     Germany  65
## 12      Greece  47
## 13     Hungary 148
## 14     Ireland  65
## 15       Italy  49
## 16      Latvia  97
## 17   Lithuania 115
## 18  Luxembourg  47
## 19       Malta  52
## 20 Netherlands 111
## 21      Poland  84
## 22    Portugal  61
## 23     Romania  65
## 24    Slovakia 159
## 25    Slovenia 139
## 26       Spain  50
## 27      Sweden  56

Now let’s visualize our calculated TDI values.

TDI_plot <- ggplot(x, aes(x = tdi, y = reorder(reporter, desc(tdi)))) +
  geom_col(aes(fill = tdi), width = 0.6, show.legend = FALSE) +
  labs(title = "Trade Dependence Index for EU-27 Economies (2020)", x = NULL, y = NULL) +
  theme_minimal()
TDI_plot

As can be seen from the chart, there was a considerable variation in the degree of trade openness between these economies in 2020, with Slovakia, Hungary, Czechia and Slovenia much more dependent on trade than the other examined economies. Note that it is possible for the value of trade to exceed the value of production, hence there are index values of over 100 per cent for several economies.

Import Penetration

What does it tell us? The import penetration rate shows to what degree domestic demand (the difference between GDP and net exports) is satisfied by imports. Calculated at the sectoral level it is termed as the self-sufficiency ratio. The index may be used as the basis of specific policy objectives targeting self-sufficiency. It may provide an indication of the degree of vulnerability to certain types of external shocks.

Definition: The ratio of total imports to domestic demand, as a percentage. Range of values: Ranges from 0 (with no imports) to 100 per cent when all domestic demand is satisfied by imports only (no domestic production).

Mathematical definition:\(IP=\frac{\sum_{s}M_{sd}}{GDP_d-\sum_{s}X_{ds}+\sum_{s}M_{sd}}100\)

Limitations: The import penetration index is biased upward by re-exports (can be corrected for in principle). Will tend to be negatively correlated with economic size. A low import penetration ratio (complete self-sufficiency) may be an inappropriate policy target from an efficiency perspective.

We start again with the data object containing data from UN Comtrade. This time we’ll be calculating Import Penetration for the Italy in years 2016-2020. The process to build our data frame is the same as above (we only select a different economy). After that we can calculate Import Penetration index for the Italy following the operations as shown in the formula, and we round the index values.

IP <- TradeData %>% 
  filter(reporter == "Italy") %>% 
    select(year, trade_direction, trade_value_usd) %>%
  spread(trade_direction, trade_value_usd)
gdp <- WDI(indicator= c("GDP" = "NY.GDP.MKTP.CD"), country="ITA", start=2018, end=2024)
IP <- merge(IP, gdp, by = "year") %>% select(year, Export, Import, GDP)
IP$Domestic_Demand <- IP$GDP - IP$Export + IP$Import
IP$ip <- (IP$Import / IP$Domestic_Demand) * 100
IP <- IP %>% select(year, ip) %>% mutate(ip = round(ip, 0))
IP
##   year ip
## 1 2018 25
## 2 2019 24
## 3 2020 23
## 4 2021 27
## 5 2022 33
## 6 2023 28
## 7 2024 NA

In a second example let’s calculate Import Penetration index for the same set of EU-27 economies in 2020, and display the values in a tidy bar chart.

In this case we can reuse x data frame from the previous section, since it already includes the variables we need (Import, Exports and GDP). We only need to remove tdi column, as it is redundant, and create ip column to save values of the new indicator.

x <- x %>% select(-tdi)
x$Domestic_Demand <- x$GDP - x$Export + x$Import
x$ip <- (x$Import / x$Domestic_Demand) * 100
x$ip <- round(x$ip, 0)
x[, c("reporter", "ip")]
##       reporter ip
## 1      Austria 38
## 2      Belgium 56
## 3     Bulgaria 47
## 4      Croatia 39
## 5       Cyprus 28
## 6      Czechia 74
## 7      Denmark 28
## 8      Estonia 54
## 9      Finland 25
## 10      France 21
## 11     Germany 31
## 12      Greece 26
## 13     Hungary 75
## 14     Ireland 28
## 15       Italy 23
## 16      Latvia 49
## 17   Lithuania 58
## 18  Luxembourg 26
## 19       Malta 30
## 20 Netherlands 56
## 21      Poland 42
## 22    Portugal 32
## 23     Romania 34
## 24    Slovakia 80
## 25    Slovenia 70
## 26       Spain 25
## 27      Sweden 28

Again let’s create the bar chart.

IP_plot <- ggplot(x, aes(x = ip, y = reorder(reporter, desc(ip)))) +
  geom_col(aes(fill = ip), width = 0.6, show.legend = FALSE) +
  labs(title = "Import Penetration Index for EU-27 Economies (2020)", x = NULL, y = NULL) +
  theme_minimal()
IP_plot

Import penetration indices are revealed to be very high for Slovakia, Hungary, Czechia and Slovenia in 2020.

Export Propensity.

The index shows the overall degree of reliance of domestic producers on foreign markets. It is similar to the trade dependence index, but may provide a better indicator of vulnerability to certain types of external shocks (e.g., falls in export prices or changes in exchange rates). It may be a policy target.

Definition: The ratio of exports to GDP, defined as a percentage.

Mathematical definition: \(EP=\frac{\sum_{s}X_{ds}}{GDP_d}100\)

where d is the country under study, s is the set of all other countries, X is total bilateral exports, and GDP is gross domestic product (of country d). In words, the numerator is total exports from d, and the denominator is the GDP of d.

Range of values: The ratio is expressed as a percentage and it ranges from zero (with no exports) to 100 (with all domestic production exported).

Limitations: The export propensity index is biased upward by re-exports (can be corrected for in principle). Will tend to be negatively correlated with economic size. A high export propensity may be an inappropriate policy target from an efficiency perspective.

We’ll now calculate Export Propensity index for Portugal in 2018-2024. We start with subsetting the data object to extract data on Portugal exports and selecting relevant variables. After that we rename the variable trade_value_usd as Export.

EP <- TradeData %>% 
  filter(reporter == "Portugal" & trade_direction == "Export") %>% 
  select(year, trade_value_usd) %>%
  rename(Export=trade_value_usd)

After that, we make an API call to WDI database to obtain GDP values for Portugal over the same time period. Finally, we can calculate EP indices.

gdp <- WDI(indicator= c("GDP" = "NY.GDP.MKTP.CD"), country="PRT", start=2018, end=2024)
EP <- merge(EP, gdp, by = "year")  %>% select(year, Export, GDP)
EP$ep <- (EP$Export / EP$GDP) *100
EP$ep <- round(EP$ep, 0)
EP %>% select(year, ep)
##   year ep
## 1 2018 31
## 2 2019 28
## 3 2020 27
## 4 2021 29
## 5 2022 32
## 6 2023 29
## 7 2024 NA

Now let’s calculate EP indices for EU-27 economies in 2020. First, we go back to x data frame and restore it to its original form, so that we only have reporter, Export and GDP columns.

Now we can easily calculate EP index and store the values in ep column. After that we run ggplot() with geom_col() to make another bar chart.

x <- x %>% select(reporter, Export, GDP)
x$ep <- (x$Export / x$GDP) * 100
x$ep <- round(x$ep, 0)
x %>% select(reporter, ep)
##       reporter ep
## 1      Austria 37
## 2      Belgium 56
## 3     Bulgaria 45
## 4      Croatia 29
## 5       Cyprus 12
## 6      Czechia 77
## 7      Denmark 30
## 8      Estonia 53
## 9      Finland 24
## 10      France 18
## 11     Germany 35
## 12      Greece 18
## 13     Hungary 76
## 14     Ireland 42
## 15       Italy 26
## 16      Latvia 46
## 17   Lithuania 57
## 18  Luxembourg 18
## 19       Malta 17
## 20 Netherlands 59
## 21      Poland 42
## 22    Portugal 27
## 23     Romania 28
## 24    Slovakia 80
## 25    Slovenia 70
## 26       Spain 24
## 27      Sweden 28
EP_plot <- ggplot(x, aes(x = ep, y = reorder(reporter, desc(ep)))) +
  geom_col(aes(fill = ep), width = 0.6, show.legend = FALSE) +
  labs(title = "Export Propensity Index for EU-27 Economies (2020)", x = NULL, y = NULL) + 
  theme_minimal()
EP_plot

It is revealed that once again Slovakia, Czechia, Hungary and Slovenia have the highest values for Export Propensity Index.

Marginal Propensity to Import.

What does it tell us? The marginal propensity to import (MPM) is a measure of the extent to which imports are induced by a change in incomes. The relevance for policymakers depends on the cycle of the economy. With higher MPM, in an economic downturn with a fall in GDP, there will also be a significant fall in imports as compared with lower a MPM. More generally, a higher MPM reduces the multiplier effect of an increase in GDP.

Definition: The ratio of the change in total imports to the change in GDP over a defined period (typically one year).

Mathematical definition: \(MPM=\frac{\vartriangle\sum_{s}M_{sd}}{\vartriangle GDP_d}100\)

where d is the country under study, s is the set of all other countries, ∆ is the change operator, M is total bilateral imports and GDP is gross domestic product (of country d). In words, the numerator is the change in total imports to d over a given period (usually one year), and the denominator is the change in the GDP of d over the same period.

Range of values: In macroeconomic theory ranges between 0 (with no part of extra GDP spent on additional imports) and 1 when the whole extra GDP created is spent on imports.

Limitations: The MPM is not a constant and can vary over time, so care should be taken in using it as an input to policy decisions. Calculations based on annual data only approximate the true value, and may lie outside of the theoretically sensible range.

This time we’ll find Marginal Propensity Import indices for France over 2018-2024.

MPM <- TradeData %>% 
  filter(reporter == "France" & trade_direction == "Import") %>% 
  select(year, trade_value_usd) %>%
  rename(Import=trade_value_usd)
gdp <- WDI(indicator= c("GDP" = "NY.GDP.MKTP.CD"), country="FRA", start=2018, end=2024)
MPM <- merge(MPM, gdp, by = "year")  %>% select(year, Import, GDP)
MPM
##   year       Import           GDP
## 1 2018 659374522338 2781576320884
## 2 2019 643208112669 2722793515172
## 3 2020 580805912500 2647926055110
## 4 2021 715858934244 2966433692008
## 5 2022 819397544528 2796302210399
## 6 2023 777131874767 3051831611385

At this point we need to calculate values for change in total imports and GDP over the examined period of time. We do that by running lag() in our subtraction. This function will automatically select the Import value related to the preceding year.

MPM$dImport <- MPM$Import - lag(MPM$Import)
MPM$dGDP <- MPM$GDP - lag(MPM$GDP)
MPM$mpm <- MPM$dImport / MPM$dGDP
MPM$mpm <- round(MPM$mpm, 2)
MPM %>% select(year, mpm)
##   year   mpm
## 1 2018    NA
## 2 2019  0.28
## 3 2020  0.83
## 4 2021  0.42
## 5 2022 -0.61
## 6 2023 -0.17

Now let’s calculate MPM indices for EU-27 economies over 2018-2024 period and display results in a line chart. First, let’s compile necessary data in a new x data frame.

x <- TradeData %>% 
  filter(reporter %in% EU.27 & trade_direction == "Import") %>% 
  select(reporter, year, trade_value_usd)
gdp <- WDI(indicator= c("GDP" = "NY.GDP.MKTP.CD"), 
           country=c("AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "IRL", "ITA", "LVA", "LTU", "LUX", "MLT", "NLD", "POL", "PRT", "ROU", "SVK", "SVN", "ESP", "SWE"), start=2018, end=2024)
gdp$country <- ifelse(gdp$country == "Slovak Republic", "Slovakia", gdp$country)
x <- merge(x, gdp, by.x = c("year", "reporter"),
           by.y = c("year", "country")) %>% 
  select(year, reporter, trade_value_usd, GDP)

Now let’s make our calculations and then reshape the data to have MPM index values in separate columns for each economy. We will also remove the first line of our final data frame since it’s populated with NAs only.

Note use of the function mutate() below, which adds new variables to a data frame and preserve the existing ones. It preserves the number of rows in the dataset. If calculation is made for grouped variables, than one same value will be saved into the specified column across all the rows corresponding to a given combination of grouping variables. This should be paid attention to when you conduct further calculations, and it is a good practice to use ungroup() function on a dataset after a given calculation is finalized and the grouping becomes redundant.

x <- x %>% 
  group_by(reporter) %>%
  mutate(dImports = trade_value_usd - lag(trade_value_usd, n = 1, default = NA)) %>% 
  mutate(dGDP = GDP - lag(GDP, n = 1, default = NA)) %>%
  mutate(MPM = dImports / dGDP) %>% 
  ungroup() 
x <- x %>% 
  select(year, reporter, MPM) %>%
  spread(reporter, MPM)
x <- x[-1,]

As the last step, we will run ggplot() to visualize our time series.

Typically, it’s easier to graph data with ggplot() if the data is in a long format, so we will reshape the data frame back to longer format so there is one observation for each country-year grouping. Then we will add a geom_line() function to specify that we want a time-series (line) graph. We will also color code line charts for each economy.

x <- x %>% 
  pivot_longer(cols = Austria:`Sweden`, names_to = "country", values_to = "mpm")
MPM_plot <-  ggplot(x, aes(x = year, y = mpm, color = country)) + 
      geom_line() + 
      scale_color_brewer(palette = "Set1") +
      labs(title = "MPM for EU-27 economies (2018-2024)", x = NULL, y = NULL, color = "Economies") +
      theme_minimal() + 
  theme(legend.position="bottom") + guides(fill = guide_legend(nrow = 1))
MPM_plot

The MPM indices were calculated year-on-year. The resulting chart reveals that in 2018 24 out of 27 economies experienced a significant decrease in MPM indices, that rebounded in 2020. Note that in practice the calculated values can in fact be negative or exceed unity.

Trade Performance.

Trade Performance refers to the assessment and measurement of how well trading activities or financial transactions perform over time. It typically includes evaluating key metrics such as profitability, risk exposure, win/loss ratio, trade frequency, and other indicators that help optimize trading strategies and support informed decision-making.

Growth Rate of Exports.

The growth rate is one of the most common indicators used when assessing the progress of an economy in any area of economic activity. Often the rate is calculated at level of product groups to identify ‘dynamic sectors.’ Comparison of such indicators over many countries might be of interest to producer or exporter associations, investors, policymakers and trade negotiators.

Definition: The annual growth rate is the percentage change in the value of exports between two adjacent time periods. The compound growth rate is the annual growth rate required to generate a given total growth over a given time period. If the time period is a single year (n is equal to 1), this is the same as the annual growth rate.

The growth rate may also be calculated for a subset of destinations, or for a subset of products, with appropriate modification. The growth rate can also be calculated for imports and/or trade (imports plus exports).

Mathematical definition: \(TDI=[(\frac{\sum_{sw}X^1_{sw}}{\sum_{sw}X^0_{sw}})^\frac{1}{n}-1]100\)

Range of values: The growth rate is a percentage. It can take a value between -100 per cent (if trade ceases) and +∞. A value of zero indicates that the value of trade has remained constant.

Limitations: Does not explain the source of growth. When evaluating long periods need to be careful of changes in measurement and methods. Growth rates assessed on nominal trade figures may be distorted by exchange rate movements and other factors in the short run.

GRX <- TradeData %>% 
  filter(reporter %in% c("Germany") & trade_direction == "Export") %>% 
  select(reporter, year, trade_value_usd)
GRX <- GRX %>% 
   arrange(desc(year))
GRX
## # A tibble: 12 × 3
##    reporter  year trade_value_usd
##    <chr>    <dbl>           <dbl>
##  1 Germany   2024         1.69e12
##  2 Germany   2023         1.70e12
##  3 Germany   2022         1.69e12
##  4 Germany   2021         1.64e12
##  5 Germany   2020         1.39e12
##  6 Germany   2019         1.49e12
##  7 Germany   2018         1.56e12
##  8 Germany   2017         1.43e12
##  9 Germany   2016         1.34e12
## 10 Germany   2015         1.33e12
## 11 Germany   2014         1.50e12
## 12 Germany   2013         1.45e12

To calculate compound annual export growth rate for Germany we will need to take more steps. Calculate annual growth rates for Germany.

GRX$Annual_growth <- (GRX$trade_value_usd / lead(GRX$trade_value_usd)-1)*100
GRX$Annual_growth <- round(GRX$Annual_growth, 4)
# calculate compound annual growth rates for Germany for 2023 for reference
# note that n of 12 is used since there are 9 periods of growth from 2011 till 2023
((GRX$trade_value_usd[2]/GRX$trade_value_usd[10])^(1/12)-1)*100
## [1] 2.062802
# calculate compound annual growth rates for Germany for 2018 for reference
# note that n of 5 is used since there are 5 periods of growth from 2011 till 2018
((GRX$trade_value_usd[7]/GRX$trade_value_usd[10])^(1/7)-1)*100
## [1] 2.34397

Calculate compound annual growth rates over the full period of 2011-2020.

GRX$Compound_Growth <- NA
GRX$n <- NA
GRX$n[1:9] <- 1/c(9:1)
GRX$Compound_Growth[-10] <- ((GRX$trade_value_usd[1:9] / GRX$trade_value_usd[10]) ^ GRX$n[1:9] - 1) * 100
GRX$Compound_Growth[-10] <- round(GRX$Compound_Growth[-10],4)
GRX[, c(2,4,5)]
## # A tibble: 12 × 3
##     year Annual_growth Compound_Growth
##    <dbl>         <dbl>           <dbl>
##  1  2024        -0.350           2.72 
##  2  2023         0.665           3.11 
##  3  2022         3.09            3.46 
##  4  2021        18.0             3.53 
##  5  2020        -7.19            0.849
##  6  2019        -4.43            2.97 
##  7  2018         9.22            5.56 
##  8  2017         6.98            3.77 
##  9  2016         0.658           0.658
## 10  2015       -11.3            NA    
## 11  2014         3.26            2.72 
## 12  2013        NA               3.11

In our second example we will calculate compound growth rates for EU-27, Norway, Switzerland and rest of the world (ROW) over a period of 10 years (2015-2024).

EU.27 <- c("Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czechia", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden")

group <- c(EU.27, "Switzerland", "Norway")

x <- TradeData %>%
  filter(reporter %in% group & trade_direction == "Export") %>%
  select(reporter, year, trade_value_usd)
unique(x$reporter)
##  [1] "Austria"     "Belgium"     "Bulgaria"    "Croatia"     "Cyprus"     
##  [6] "Czechia"     "Denmark"     "Estonia"     "Finland"     "France"     
## [11] "Germany"     "Greece"      "Hungary"     "Ireland"     "Italy"      
## [16] "Latvia"      "Lithuania"   "Luxembourg"  "Malta"       "Netherlands"
## [21] "Norway"      "Poland"      "Portugal"    "Romania"     "Slovakia"   
## [26] "Slovenia"    "Spain"       "Sweden"      "Switzerland"
x
## # A tibble: 344 × 3
##    reporter  year trade_value_usd
##    <chr>    <dbl>           <dbl>
##  1 Austria   2013   166273910255.
##  2 Belgium   2013   318244235353.
##  3 Bulgaria  2013    29510574320 
##  4 Croatia   2013    12741618485 
##  5 Cyprus    2013     2136943890.
##  6 Czechia   2013   161524152111 
##  7 Denmark   2013   110469532387 
##  8 Estonia   2013    18284136368 
##  9 Finland   2013    74445385637 
## 10 France    2013   567987697540 
## # ℹ 334 more rows

In the next few steps we reshape the data and calculate total export flows from EUROZONE region in each year.

x <- x %>% spread(reporter, trade_value_usd) %>% 
  arrange(desc(year))
x$EU.27 <- rowSums(x[,which(names(x) %in% EU.27)], na.rm = T)
x <- x %>% select(year, Switzerland, Norway, EU.27)
x
## # A tibble: 12 × 4
##     year   Switzerland        Norway   EU.27
##    <dbl>         <dbl>         <dbl>   <dbl>
##  1  2024 446304800824. 168047733520. 5.87e12
##  2  2023 419922543424. 176896550419. 6.81e12
##  3  2022 400057174592. 276926311862. 6.81e12
##  4  2021 379770927043. 173813766176. 6.32e12
##  5  2020 318580420584.  82748920958. 5.20e12
##  6  2019 313685932751. 104029881468. 5.52e12
##  7  2018 310523862211. 123040316873. 5.68e12
##  8  2017 299331427819. 101976020160. 5.14e12
##  9  2016 302499429349.  89628326847  4.70e12
## 10  2015 289629055115. 103785482320. 4.65e12
## 11  2014 311292919173. 144611289843  5.37e12
## 12  2013 357909509746. 155350552822  5.26e12

Then, we calculate total export flows in each year for the rest of the world group (ROW).

ROW <- TradeData %>%
  filter(!reporter %in% group & trade_direction == "Export") %>%
  group_by(year) %>% 
  summarize(ROW = sum(trade_value_usd, na.rm = T)) 
x <- x %>% left_join(ROW, by = "year")
x
## # A tibble: 12 × 5
##     year   Switzerland        Norway   EU.27     ROW
##    <dbl>         <dbl>         <dbl>   <dbl>   <dbl>
##  1  2024 446304800824. 168047733520. 5.87e12 8.65e12
##  2  2023 419922543424. 176896550419. 6.81e12 1.51e13
##  3  2022 400057174592. 276926311862. 6.81e12 1.61e13
##  4  2021 379770927043. 173813766176. 6.32e12 1.48e13
##  5  2020 318580420584.  82748920958. 5.20e12 1.16e13
##  6  2019 313685932751. 104029881468. 5.52e12 1.25e13
##  7  2018 310523862211. 123040316873. 5.68e12 1.29e13
##  8  2017 299331427819. 101976020160. 5.14e12 1.17e13
##  9  2016 302499429349.  89628326847  4.70e12 1.06e13
## 10  2015 289629055115. 103785482320. 4.65e12 1.11e13
## 11  2014 311292919173. 144611289843  5.37e12 1.27e13
## 12  2013 357909509746. 155350552822  5.26e12 1.28e13

Now let’s once again use lead() function when calculating annual growth rate (AG) for each economy.

x$AG_Norway <- (x$Norway / lead(x$Norway)-1)*100
x$AG_Switzerland <- (x$Switzerland / lead(x$Switzerland)-1)*100
x$AG_EU.27 <- (x$EU.27 / lead(x$EU.27)-1)*100
x$AG_ROW <- (x$ROW / lead(x$ROW)-1)*100
x <- x[-10, c(1,6:9)]
x
## # A tibble: 11 × 5
##     year AG_Norway AG_Switzerland AG_EU.27 AG_ROW
##    <dbl>     <dbl>          <dbl>    <dbl>  <dbl>
##  1  2024     -5.00           6.28 -13.7    -42.8 
##  2  2023    -36.1            4.97  -0.0377  -5.81
##  3  2022     59.3            5.34   7.79     8.45
##  4  2021    110.            19.2   21.5     27.9 
##  5  2020    -20.5            1.56  -5.83    -7.50
##  6  2019    -15.5            1.02  -2.90    -2.60
##  7  2018     20.7            3.74  10.6      9.59
##  8  2017     13.8           -1.05   9.30    10.7 
##  9  2016    -13.6            4.44   1.23    -4.61
## 10  2014     -6.91         -13.0    2.05    -1.13
## 11  2013     NA             NA     NA       NA

Now let’s create a line plot fo see the trend over time. We again will reshape the data to long format for easier plotting.

x <- x %>% 
  pivot_longer(cols = AG_Norway:AG_ROW, names_to = "country", 
               names_prefix = "AG_", values_to = "ag")
GRX_plot <- ggplot(x, aes(x = year, y = ag, color = country)) + 
  geom_line() +
  labs(title = "Selected Export Growth Rates (2013-2024)", x = NULL, y = NULL, 
       color = "Country Group") +
  scale_color_brewer(palette = "Set1") +
  theme_minimal()
GRX_plot

Normalized Trade Balance.

The normalized trade balance represents a record of a country’s trade transactions with the rest of the world normalized on its own total trade. In general, economists expect that the trade balance will be zero in the long run, thus imports are financed by exports, but it may vary considerably over shorter periods.

Definition: The trade balance (total exports less total imports) as fraction of total trade (exports plus imports).

Mathematical definition: \(NTB=\frac{\sum_{sw}X_{sw}-\sum_{ws}M_{ws}}{\sum_{sw}X_{sw}+\sum_{ws}M_{ws}}\)

where s is the set of countries in the source, w is the set of countries in the world, X is the bilateral total export flow, and M is the bilateral total import flow in the end period. In words, we take total exports from the source region less total imports to the source region, and divide by the total trade of the source region.

Range of values: The index range is between -1 and +1, which allows unbiased comparisons across time, countries and sectors. A value of zero indicates trade balance.

Limitations: The economic reasons for a trade surplus/deficit are complex, and the index cannot directly help shed light on them. Potential for misuse high, especially with respect to bilateral balances.

We are going to calculate Normalized Trade Balance (NTB) for a set of countries in 2023.

group <- c("Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czechia", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden")
NTB <- TradeData %>% 
  filter(reporter %in% group & year == 2020) %>% 
  select(reporter, trade_direction, trade_value_usd)
NTB <- NTB %>% spread(trade_direction, trade_value_usd)
NTB$Normalized_Trade_Balance <- (NTB$Export - NTB$Import) / (NTB$Export + NTB$Import)
NTB$Normalized_Trade_Balance <- round(NTB$Normalized_Trade_Balance, 2)
NTB
## # A tibble: 27 × 4
##    reporter        Export        Import Normalized_Trade_Balance
##    <chr>            <dbl>         <dbl>                    <dbl>
##  1 Austria  162145129017. 164635579304.                    -0.01
##  2 Belgium  295143761844. 294246686005.                     0   
##  3 Bulgaria  31914703883.  35027243633.                    -0.05
##  4 Croatia   16991280298   26095988209                     -0.21
##  5 Cyprus     3137095808.   8728558941.                    -0.47
##  6 Czechia  192307379805  171440208263                      0.06
##  7 Denmark  106871154269.  95778398379.                     0.05
##  8 Estonia   16901599064.  17764140293.                    -0.02
##  9 Finland   65606975840.  68266522010.                    -0.02
## 10 France   487987460595. 580805912500.                    -0.09
## # ℹ 17 more rows

Now let’s create a bar chart plot to examine the results.

NTB_plot <- NTB %>% 
  ggplot(aes(x = Normalized_Trade_Balance, y = reorder(reporter, desc(reporter)))) +
  geom_bar(aes(fill = Normalized_Trade_Balance), stat = 'identity', width = 0.6, show.legend = F) +
  labs(title = "Normalized Trade Balance for Selected Economies (2023)", x = NULL, y = NULL) +
  geom_vline(xintercept = 0) +
  theme_minimal()
NTB_plot

Export/Import Coverage.

This is an alternative to the normalized trade balance. It tells us whether or not a country’s imports are fully paid for by exports in a given year. In general, economists expect that the trade balance will be zero in the long run, thus imports are financed by exports, but it may vary considerably over shorter periods.

Definition: The ratio of total exports to total imports.

Mathematical definition: \(XMC=\frac{\sum_{sw}X_{sw}}{\sum_{ws}M_{ws}}\)

where s is the set of countries in the source, w is the set of countries in the world, X is the bilateral total export flow, and M is the bilateral total import flow in the end period. In words, we take total exports from the source region, and divide by the total imports of the source region.

Range of values: The values for this index range from 0 when there are no exports to +∞ when there are no imports. A ratio of 1 signals full coverage of imports with exports (trade balance).

Limitations: Same as for the normalized trade balance. The economic reasons for a trade surplus/deficit are complex, and the index cannot directly help shed light on them. Potential for misuse high, especially with respect to bilateral balances.

To calculate the Export/Import Coverage (XMC) we just need to divide total exports by total import for each economy. To do that we can re-use the previous data frame, making sure to remove NTB variable as we don’t need it anymore.

XMC <- NTB[,-4]
XMC$XM_Coverage <- XMC$Export / XMC$Import
XMC$XM_Coverage <- round(XMC$XM_Coverage, 2)
XMC
## # A tibble: 27 × 4
##    reporter        Export        Import XM_Coverage
##    <chr>            <dbl>         <dbl>       <dbl>
##  1 Austria  162145129017. 164635579304.        0.98
##  2 Belgium  295143761844. 294246686005.        1   
##  3 Bulgaria  31914703883.  35027243633.        0.91
##  4 Croatia   16991280298   26095988209         0.65
##  5 Cyprus     3137095808.   8728558941.        0.36
##  6 Czechia  192307379805  171440208263         1.12
##  7 Denmark  106871154269.  95778398379.        1.12
##  8 Estonia   16901599064.  17764140293.        0.95
##  9 Finland   65606975840.  68266522010.        0.96
## 10 France   487987460595. 580805912500.        0.84
## # ℹ 17 more rows

Let’s display results in a bar chart.

XMC_plot <- ggplot(XMC, aes(x = XM_Coverage, y = reorder(reporter, desc(reporter)))) +
  geom_bar(fill = 'dodgerblue4', stat='identity', width = 0.6, show.legend = FALSE) +
  labs(title = "Export/Import Coverage for Selected Economies (2023)", x = NULL, y = NULL) +
  geom_vline(xintercept = 1, color = 'red', linewidth = 1) +
  theme_minimal()
XMC_plot