Current Account, Goods and Services, Net, US Dollars - BGS_BP6_USD

Data - IMF

FREQ

Code
BGS_BP6_USD |>
  group_by(FREQ) |>
  summarise(Nobs = n()) |>
  arrange(-Nobs) |>
  print_table_conditional()
FREQ Nobs
Q 18595
A 7778

REF_AREA

Code
BGS_BP6_USD |>
  left_join(REF_AREA, by = "REF_AREA") |>
  group_by(REF_AREA, Ref_area) |>
  summarise(Nobs = n()) |>
  arrange(-Nobs) |>
  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 .}

TIME_PERIOD

Code
BGS_BP6_USD |>
  group_by(TIME_PERIOD) |>
  summarise(Nobs = n()) |>
  arrange(desc(TIME_PERIOD)) |>
  print_table_conditional()

Current Accounts

Largest CA Deficits

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         TIME_PERIOD %in% c("2018", "2019", "2020")) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  select(REF_AREA, Ref_area, TIME_PERIOD, OBS_VALUE) |>
  spread(TIME_PERIOD, OBS_VALUE) |>
  filter(abs(`2018`) > 10000, `2018` < 0) |>
  arrange(`2018`) %>%
  mutate_at(vars(-1, -2), funs(round(./1000))) |>
  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 .}

Largest CA Surpluses

Javascript

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         TIME_PERIOD %in% c("2018", "2019", "2020")) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  select(REF_AREA, Ref_area, TIME_PERIOD, OBS_VALUE) |>
  spread(TIME_PERIOD, OBS_VALUE) |>
  filter(abs(`2018`) > 10000, `2018` > 0) |>
  arrange(-`2018`) %>%
  mutate_at(vars(-1, -2), funs(round(./1000))) |>
  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 .}

png

Code
i_g("bib/imf/BGS_BP6_USD_ex1.png")

png - With 2020 (Covid-19)

Code
i_g("bib/imf/BGS_BP6_USD_ex1b.png")

Germany, Europe, China

All

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("DE", "U2", "CN")) |>
  year_to_date2() |>
  select(date, OBS_VALUE, REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |> 
              filter(iso2c == "1W") |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, NY.GDP.MKTP.CD = value), 
            by = c("date")) |>
  mutate(value = (10^6)*OBS_VALUE/NY.GDP.MKTP.CD) |>
  select(-OBS_VALUE) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  mutate(Ref_area = ifelse(REF_AREA == "U2", "Europe", Ref_area)) |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + 
  geom_line(aes(x = date, y = value, color = color)) + 
  theme_minimal() + add_flags +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 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(-60, 60, 0.1),
                     labels = scales::percent_format(accuracy = .1)) +
  xlab("") + ylab("Current Account (% of World GDP)") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

1990-

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("DE", "U2", "CN")) |>
  year_to_date2() |>
  select(date, OBS_VALUE, REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |> 
              filter(iso2c == "1W") |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, NY.GDP.MKTP.CD = value), 
            by = c("date")) |>
  mutate(OBS_VALUE = (10^6)*OBS_VALUE/NY.GDP.MKTP.CD) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  filter(date >= as.Date("1990-01-01")) |>
  mutate(Ref_area = ifelse(REF_AREA == "U2", "Europe", Ref_area)) |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + 
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  theme_minimal() + add_flags +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 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(-60, 60, 0.1),
                     labels = scales::percent_format(accuracy = .1)) +
  xlab("") + ylab("Current Account (% of World GDP)") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

All CA

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         TIME_PERIOD == "2019") |>
  select(OBS_VALUE, REF_AREA) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  select(REF_AREA, Ref_area, OBS_VALUE) |>
  arrange(OBS_VALUE) |>
  mutate(OBS_VALUE = round(OBS_VALUE/1000)) |>
  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 .}

Balance of Payments (Bn$)

Austria, Netherlands, Denmark, Sweden

$

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("SE", "AT", "NL","DK")) |>
  year_to_date2() |>
  left_join(REF_AREA, by = "REF_AREA") |>
  mutate(OBS_VALUE = OBS_VALUE/1000) |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + 
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  theme_minimal() + add_flags +
  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 = seq(-20000, 400000, 10),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Current Account") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

Lebanon, France, Italy

$

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("LB", "FR", "IT")) |>
  year_to_date2() |>
  left_join(REF_AREA, by = "REF_AREA") |>
    mutate(OBS_VALUE = OBS_VALUE/1000) |>
  left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + add_flags + theme_minimal() +
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  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 = seq(-20000, 400000, 10),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) +
  xlab("") + ylab("Net Current Account") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

France, Germany, Italy

$

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("DE", "FR", "IT")) |>
  year_to_date2() |>
  left_join(REF_AREA, by = "REF_AREA") |>
    mutate(OBS_VALUE = OBS_VALUE/1000) |>
  left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + add_flags + theme_minimal() +
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  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 = seq(-20000, 400000, 50),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

% of GDP

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("DE", "FR", "IT")) |>
  year_to_date2() |>
  select(date, OBS_VALUE, REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |> 
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(REF_AREA = iso2c, date, NY.GDP.MKTP.CD = value), 
            by = c("REF_AREA", "date")) |>
  mutate(value = (10^6)*OBS_VALUE/NY.GDP.MKTP.CD) |>
  left_join(REF_AREA, by = "REF_AREA") |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + add_flags + 
  geom_line(aes(x = date, y = value, color = color)) + 
  theme_minimal() + 
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 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(-60, 60, 1),
                     labels = scales::percent_format(accuracy = 1)) +
  xlab("") + ylab("Current Account (% of GDP)") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

% of World GDP

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("DE", "FR", "IT")) |>
  year_to_date2() |>
  select(date, OBS_VALUE, REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |> 
              filter(iso2c == "1W") |>
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(date, NY.GDP.MKTP.CD = value), 
            by = c("date")) |>
  mutate(value = (10^6)*OBS_VALUE/NY.GDP.MKTP.CD) |>
  left_join(REF_AREA, by = "REF_AREA") |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + add_flags + 
  geom_line(aes(x = date, y = value, color = color)) + 
  theme_minimal() + 
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 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(-60, 60, 0.1),
                     labels = scales::percent_format(accuracy = .1)) +
  xlab("") + ylab("Current Account (% of World GDP)") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

Saudi Arabia, Norway

$

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("NO", "SA", "VE")) |>
  year_to_date2() |>
  left_join(REF_AREA, by = "REF_AREA") |>
  mutate(Ref_area = ifelse(REF_AREA == "VE", "Venezuela", Ref_area)) |>
    mutate(OBS_VALUE = OBS_VALUE/1000) |>
  left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + add_flags + 
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  theme_minimal() +
  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 = seq(-20000, 400000, 50),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

% of GDP

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("NO", "SA", "VE")) |>
  year_to_date2() |>
  select(date, OBS_VALUE, REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |> 
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(REF_AREA = iso2c, date, NY.GDP.MKTP.CD = value), 
            by = c("REF_AREA", "date")) |>
  mutate(OBS_VALUE = (10^6)*OBS_VALUE/NY.GDP.MKTP.CD) |>
  left_join(REF_AREA, by = "REF_AREA") |>
  mutate(Ref_area = ifelse(REF_AREA == "VE", "Venezuela", Ref_area)) |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + 
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.8, 0.9)) + add_flags +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = 0.01*seq(-60, 60, 5),
                     labels = scales::percent_format(accuracy = 1)) +
  xlab("") + ylab("Current Account (% of GDP)") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")

Netherlands, Greece, Spain

$

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("NL", "ES", "GR")) |>
  year_to_date2() |>
  left_join(REF_AREA, by = "REF_AREA") |>
  mutate(OBS_VALUE = OBS_VALUE/1000) |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + 
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  theme_minimal() + 
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.8)) + add_flags +
  scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(-20000, 400000, 50),
                     labels = dollar_format(accuracy = 1, suffix = " Bn", prefix = "$ ")) + 
  xlab("") + ylab("Net Current Account")

% of GDP

Code
BGS_BP6_USD |>
  filter(FREQ == "A",
         REF_AREA %in% c("NL", "ES", "GR")) |>
  year_to_date2() |>
  select(date, OBS_VALUE, REF_AREA) |>
  left_join(NY.GDP.MKTP.CD |> 
              mutate(date = as.Date(paste0(year, "-01-01"))) |>
              select(REF_AREA = iso2c, date, NY.GDP.MKTP.CD = value), 
            by = c("REF_AREA", "date")) |>
  mutate(OBS_VALUE = (10^6)*OBS_VALUE/NY.GDP.MKTP.CD) |>
  left_join(REF_AREA, by = "REF_AREA") |>
    left_join(colors, by = c("Ref_area" = "country")) |>
ggplot() + scale_color_identity() + 
  geom_line(aes(x = date, y = OBS_VALUE, color = color)) + 
  theme_minimal() + add_flags +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 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(-60, 60, 1),
                     labels = scales::percent_format(accuracy = 1)) +
  xlab("") + ylab("Current Account (% of GDP)") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black")