Balance of Payments - BOP

Data - IMF

Main Datasets

Javascript

Code
INDICATOR |>
  filter(INDICATOR %in% gsub(".qmd$", "", list.files(pattern = "\\.qmd$"))) |>
  mutate(html = paste0('<a  target=_blank href=', INDICATOR, '.html > html </a>')) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F, escape = F) else .}

Flat

Code
INDICATOR |>
  filter(INDICATOR %in% gsub(".qmd$", "", list.files(pattern = "\\.qmd$"))) |>
  mutate(html = paste0("[html](", INDICATOR, '.html)')) %>%
  {if (is_html_output()) print_table(.) else .}
INDICATOR Indicator html
BGS_BP6_USD Current Account, Goods and Services, Net, US Dollars [html]
BCA_BP6_USD Current Account, Total, Net, US Dollars [html]
BOP_BP6_USD Net Errors and Omissions, US Dollars [html]
IFR_BP6_USD Net International Investment Position (With Fund Record), US Dollars [html]

Other Datasets

Code
INDICATOR %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

Public Debt VS IIPs (% of GDP)

2011

Code
GGXWDG_GDP |>
  select(TIME_PERIOD, REF_AREA, GGXWDG_GDP = OBS_VALUE) |>
  left_join(IFR_BP6_USD, by = c("TIME_PERIOD", "REF_AREA")) |>
  year_to_date2() |>
  rename(iso2c = REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, iso2c, NY.GDP.MKTP.CD = value),
            by = c("date", "iso2c")) |>
  filter(date == as.Date("2011-01-01")) |>
  mutate(IFR_BP6_USD_GDP = -(10^(UNIT_MULT))*OBS_VALUE / NY.GDP.MKTP.CD) |>
  left_join(iso2c, by = "iso2c") |>
  ggplot() + theme_minimal() +
  geom_point(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP)) +
  xlab("2011 Debt/GDP (%)") + ylab("2011 External Debt/GDP (%)") +
  scale_x_continuous(breaks = 0.01*seq(-100, 600, 20),
                     labels = scales::percent_format(accuracy = 1)) +
  scale_y_continuous(breaks = 0.01*seq(-600, 600, 50),
                     labels = scales::percent_format(accuracy = 1)) +
  geom_text_repel(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP, label = Iso2c)) +
  stat_smooth(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP), 
              linetype = 2, method = "lm", color = viridis(4)[2])

Code
GGXWDG_GDP |>
  select(TIME_PERIOD, REF_AREA, GGXWDG_GDP = OBS_VALUE) |>
  left_join(IFR_BP6_USD, by = c("TIME_PERIOD", "REF_AREA")) |>
  year_to_date2() |>
  rename(iso2c = REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, iso2c, NY.GDP.MKTP.CD = value),
            by = c("date", "iso2c")) |>
  filter(date == as.Date("2011-01-01")) |>
  mutate(IFR_BP6_USD_GDP = -(10^(UNIT_MULT))*OBS_VALUE / NY.GDP.MKTP.CD) |>
  left_join(iso2c, by = "iso2c") %>%
  lm(IFR_BP6_USD_GDP ~ GGXWDG_GDP, data = .) |>
  summary()
# 
# Call:
# lm(formula = IFR_BP6_USD_GDP ~ GGXWDG_GDP, data = .)
# 
# Residuals:
#     Min      1Q  Median      3Q     Max 
# -3.4816 -0.1751  0.0825  0.3863  4.4703 
# 
# Coefficients:
#              Estimate Std. Error t value Pr(>|t|)   
# (Intercept) -0.123653   0.119281  -1.037  0.30170   
# GGXWDG_GDP   0.005792   0.002125   2.725  0.00725 **
# ---
# Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# 
# Residual standard error: 0.8066 on 139 degrees of freedom
#   (46 observations effacées parce que manquantes)
# Multiple R-squared:  0.05073, Adjusted R-squared:  0.0439 
# F-statistic: 7.428 on 1 and 139 DF,  p-value: 0.007249

2011 Europe

Code
GGXWDG_GDP |>
  select(TIME_PERIOD, REF_AREA, GGXWDG_GDP = OBS_VALUE) |>
  left_join(IFR_BP6_USD, by = c("TIME_PERIOD", "REF_AREA")) |>
  year_to_date2() |>
  rename(iso2c = REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, iso2c, NY.GDP.MKTP.CD = value),
            by = c("date", "iso2c")) |>
  filter(date == as.Date("2011-01-01"),
         iso2c %in% c("FR", "DE", "IT", "PT", "ES", "GR", "NL", "IE",
                      "AT", "BE", "DK", "SE", "FI", "GB")) |>
  mutate(IFR_BP6_USD_GDP = -(10^6)*OBS_VALUE / NY.GDP.MKTP.CD) |>
  left_join(iso2c, by = "iso2c") |>
  ggplot() + theme_minimal() +
  geom_point(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP)) +
  xlab("2011 Debt/GDP (%)") + ylab("2011 External Debt/GDP (%)") +
  scale_x_continuous(breaks = 0.01*seq(-100, 600, 20),
                     labels = scales::percent_format(accuracy = 1)) +
  scale_y_continuous(breaks = 0.01*seq(-600, 600, 50),
                     labels = scales::percent_format(accuracy = 1)) +
  geom_text_repel(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP, label = Iso2c)) +
  stat_smooth(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP), 
              linetype = 2, method = "lm", color = viridis(4)[2])

Without Names

Code
GGXWDG_GDP |>
  select(TIME_PERIOD, REF_AREA, GGXWDG_GDP = OBS_VALUE) |>
  left_join(IFR_BP6_USD, by = c("TIME_PERIOD", "REF_AREA")) |>
  year_to_date2() |>
  rename(iso2c = REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, iso2c, NY.GDP.MKTP.CD = value),
            by = c("date", "iso2c")) |>
  filter(date == as.Date("2011-01-01"),
         iso2c %in% c("FR", "DE", "IT", "PT", "ES", "GR", "NL", "IE",
                      "AT", "BE", "DK", "SE", "FI", "GB")) |>
  mutate(IFR_BP6_USD_GDP = -(10^6)*OBS_VALUE / NY.GDP.MKTP.CD) |>
  left_join(iso2c, by = "iso2c") |>
  ggplot() + theme_minimal() +
  geom_point(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP)) +
  xlab("Government debt (%)") + ylab("External Debt (%)") +
  scale_x_continuous(breaks = 0.01*seq(-100, 600, 20),
                     labels = scales::percent_format(accuracy = 1)) +
  scale_y_continuous(breaks = 0.01*seq(-600, 600, 50),
                     labels = scales::percent_format(accuracy = 1)) +
  stat_smooth(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP), 
              linetype = 2, method = "lm", color = viridis(4)[2])

With Names

Code
GGXWDG_GDP |>
  select(TIME_PERIOD, REF_AREA, GGXWDG_GDP = OBS_VALUE) |>
  left_join(IFR_BP6_USD, by = c("TIME_PERIOD", "REF_AREA")) |>
  year_to_date2() |>
  rename(iso2c = REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, iso2c, NY.GDP.MKTP.CD = value),
            by = c("date", "iso2c")) |>
  filter(date == as.Date("2011-01-01"),
         iso2c %in% c("FR", "DE", "IT", "PT", "ES", "GR", "NL", "IE",
                      "AT", "BE", "DK", "SE", "FI", "GB")) |>
  mutate(IFR_BP6_USD_GDP = -(10^6)*OBS_VALUE / NY.GDP.MKTP.CD) |>
  left_join(iso2c, by = "iso2c") |>
  ggplot() + theme_minimal() +
  geom_point(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP)) +
  xlab("Government debt (%)") + ylab("External Debt (%)") +
  scale_x_continuous(breaks = 0.01*seq(-100, 600, 20),
                     labels = scales::percent_format(accuracy = 1)) +
  scale_y_continuous(breaks = 0.01*seq(-600, 600, 50),
                     labels = scales::percent_format(accuracy = 1)) +
  geom_text_repel(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP, label = Iso2c)) +
  stat_smooth(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP), 
              linetype = 2, method = "lm", color = viridis(4)[2])

With Codes

Code
GGXWDG_GDP |>
  select(TIME_PERIOD, REF_AREA, GGXWDG_GDP = OBS_VALUE) |>
  left_join(IFR_BP6_USD, by = c("TIME_PERIOD", "REF_AREA")) |>
  year_to_date2() |>
  rename(iso2c = REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, iso2c, NY.GDP.MKTP.CD = value),
            by = c("date", "iso2c")) |>
  filter(date == as.Date("2011-01-01"),
         iso2c %in% c("FR", "DE", "IT", "PT", "ES", "GR", "NL", "IE",
                      "AT", "BE", "DK", "SE", "FI", "GB")) |>
  mutate(IFR_BP6_USD_GDP = -(10^6)*OBS_VALUE / NY.GDP.MKTP.CD) |>
  left_join(iso2c, by = "iso2c") |>
  ggplot() + theme_minimal() +
  geom_point(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP)) +
  xlab("Government debt (%)") + ylab("External Debt (%)") +
  scale_x_continuous(breaks = 0.01*seq(-100, 600, 20),
                     labels = scales::percent_format(accuracy = 1)) +
  scale_y_continuous(breaks = 0.01*seq(-600, 600, 50),
                     labels = scales::percent_format(accuracy = 1)) +
  geom_text_repel(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP, label = iso2c)) +
  stat_smooth(aes(x = GGXWDG_GDP/100, y = IFR_BP6_USD_GDP), 
              linetype = 2, method = "lm", color = viridis(4)[2])

Balance of Goods and Services

United States, United Kingdom, France

Annual

Code
BG_BP6_USD |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA %in% c("US", "FR", "GB")) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  filter(n() == 2) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  year_to_date2() |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + add_flags + theme_minimal() + xlab("") + ylab("% of GDP") +
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.2)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1))

Goods, Services

Nobs

Code
BMS_BP6_USD |>
  bind_rows(BXS_BP6_USD) |>
  bind_rows(BXG_BP6_USD) |>
  bind_rows(BMG_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         TIME_PERIOD == "2018") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD, INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, Goods and Services, ", "", Indicator),
         Indicator = gsub(", US Dollars", "", Indicator)) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  group_by(REF_AREA, Ref_area) |>
  mutate(OBS_VALUE = round(100*OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"], 2)) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  select(-INDICATOR, -TIME_PERIOD) |>
  spread(Indicator, OBS_VALUE) |>
  mutate(Flag = gsub(" ", "-", str_to_lower(gsub(" ", "-", Ref_area))),
         Flag = paste0('<img src="../../icon/flag/vsmall/', Flag, '.png" alt="Flag">')) |>
  select(Flag, everything()) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F, escape = F) else .}

Italy

Code
BMS_BP6_USD |>
  bind_rows(BXS_BP6_USD) |>
  bind_rows(BXG_BP6_USD) |>
  bind_rows(BMG_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "IT") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(5)[1:4]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.23, 0.85)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 100, 5),
                     labels = percent_format(accuracy = 1),
                     limits = c(0, 0.4))

China

Code
BMS_BP6_USD |>
  bind_rows(BXS_BP6_USD) |>
  bind_rows(BXG_BP6_USD) |>
  bind_rows(BMG_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "CN") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(5)[1:4]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.25, 0.85)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1),
                     limits = c(0, 0.06))

United States

Code
BMS_BP6_USD |>
  bind_rows(BXS_BP6_USD) |>
  bind_rows(BXG_BP6_USD) |>
  bind_rows(BMG_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "US") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(5)[1:4]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.25, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1))

Germany

Code
BMS_BP6_USD |>
  bind_rows(BXS_BP6_USD) |>
  bind_rows(BXG_BP6_USD) |>
  bind_rows(BMG_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "DE") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(5)[1:4]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.23, 0.83)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 100, 5),
                     labels = percent_format(accuracy = 1))

Current Account Decomposition (% of GDP)

United States

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "US") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.2)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1))

Germany

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "DE") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1))

Netherlands

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "NL") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1))

Spain

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "ES") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1))

Greece

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "GR") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.15)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-100, 100, 5),
                     labels = percent_format(accuracy = 1))

Italy

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "IT") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.4, 0.85)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-100, 100, 1),
                     labels = percent_format(accuracy = 1))

Switzerland

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "CH") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.4, 0.85)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-100, 100, 1),
                     labels = percent_format(accuracy = 1))

Ireland

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "IR") |>
  mutate(OBS_VALUE = OBS_VALUE*10^(UNIT_MULT)) |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + xlab("") + ylab("% of GDP") +
  scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.4, 0.85)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-100, 100, 1),
                     labels = percent_format(accuracy = 1))

Current Account Decomposition (USD)

United Kingdom

% of GDP

Annual

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "GB") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1)) + 
  xlab("") + ylab("% of GDP")

Germany

% of GDP

Annual

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "DE") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1)) + 
  xlab("") + ylab("Net Current Account (% of GDP)")

Quarterly

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "Q",
         REF_AREA == "DE") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  quarter_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1)) + 
  xlab("") + ylab("Net Current Account (% of GDP)")

USD

Annual

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  filter(FREQ == "A",
         REF_AREA == "DE") |>
  left_join(INDICATOR, by = "INDICATOR") |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 10),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

Quarterly

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  filter(FREQ == "Q",
         REF_AREA == "DE") |>
  left_join(INDICATOR, by = "INDICATOR") |>
  quarter_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 10),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

France

USD

Annual

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  filter(FREQ == "A",
         REF_AREA == "FR") |>
  left_join(INDICATOR, by = "INDICATOR") |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 10),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

Quarterly

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  filter(FREQ == "Q",
         REF_AREA == "FR") |>
  left_join(INDICATOR, by = "INDICATOR") |>
  quarter_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 10),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

% of GDP

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "FR") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1)) + 
  xlab("") + ylab("Net Current Account (% of GDP)")

Argentina

% of GDP

Code
BG_BP6_USD |>
  bind_rows(BS_BP6_USD) |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  bind_rows(NGDP_USD) |>
  filter(FREQ == "A",
         REF_AREA == "AR") |>
  select(TIME_PERIOD,  INDICATOR, REF_AREA, OBS_VALUE) |>
  spread(INDICATOR, OBS_VALUE) |>
  na.omit() |>
  gather(INDICATOR, OBS_VALUE, -TIME_PERIOD, -REF_AREA) |>
  group_by(TIME_PERIOD, REF_AREA) |>
  mutate(OBS_VALUE = OBS_VALUE/OBS_VALUE[INDICATOR == "NGDP_USD"]) |>
  filter(!(INDICATOR == "NGDP_USD")) |>
  left_join(INDICATOR, by = "INDICATOR") |>
  mutate(Indicator = gsub("Current Account, ", "", Indicator),
         Indicator = gsub(", Net, US Dollars", "", Indicator)) |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(6)[1:5]) +
  geom_line(aes(x = date, y = OBS_VALUE, color = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-20, 20, 1),
                     labels = percent_format(accuracy = 1)) + 
  xlab("") + ylab("Net Current Account (% of GDP)")

Annual

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  filter(FREQ == "A",
         REF_AREA == "AR") |>
  left_join(INDICATOR, by = "INDICATOR") |>
  year_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 5),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

Quarterly

Code
BGS_BP6_USD |>
  bind_rows(BIP_BP6_USD) |>
  bind_rows(BIS_BP6_USD) |>
  filter(FREQ == "Q",
         REF_AREA == "AR") |>
  left_join(INDICATOR, by = "INDICATOR") |>
  quarter_to_date2() |>
  ggplot() + theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  geom_line(aes(x = date, y = OBS_VALUE/1000, color = Indicator, linetype = Indicator)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 1),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")