As you may know, I am a huge fan of Stata (I have to tell the real story behind that choice one day…) and like to share knowledge about coding and economics in a simple and pedagogical way when possible. Never forget that science is a collaborative effort and that the more people are intelligent and skilled all around the world, the more you will be intelligent and skilled. Knowledge is multiplicative, not additive! It is not that because you know something, I will unlearn something that I know. Stay consistent, curious, and rigorous; you will reap the benefits of your efforts at the end.
Today, I will present how to use R and, more precisely, R Studio to download the data from the International Debt Statistics from the World Bank:
https://datacatalog.worldbank.org/search/dataset/0038015.
Let me use the package wbids developed by Teal Emery, Christoph Scheuch. Their GitHub is available here: https://teal-insights.github.io/r-wbids/index.html.
First, I start to download the total debt outstanding for Sub-Saharan countries and export in an Excel file. The packages wbids and writexl have been previously installed:
setwd("C:\\Users\\jamel\\Dropbox\\Latex\\PROJECTS\\25-02-euro-commission\\IDS")
# Install the package and load it
#install.packages("wbids")
library(wbids)
# Get total external debt stocks for the SSA country from 2000 onward
debt <- ids_get(
geographies = c("AGO", "BWA", "BDI", "CMR", "CPV", "CAF", "TCD", "COM", "COG", "COD",
"BEN", "ETH", "GAB", "GMB", "GHA", "GIN", "GNB", "GNQ", "CIV", "KEN",
"LSO", "LBR", "MDG", "MWI", "MLI", "MRT", "MUS", "MOZ", "NER", "NGA",
"REU", "ZWE", "RWA", "STP", "SEN", "SYC", "ERI", "SLE", "SOM", "DJI",
"NAM", "SDN", "SWZ", "TZA", "TGO", "UGA", "BFA", "ZMB"), # SSA countries
series = "DT.DOD.DECT.CD" # External debt stocks, total
)
# Install the package and load it
#install.packages("writexl")
library(writexl)
# Export the data on Excel
write_xlsx(debt, path = "debt.xlsx")
It produces the following Excel file:

I can also create several files for the bilateral stocks (Total external debt, Total debt service, Public and publicly guaranteed bilateral debt) from big donors to Sub-Saharan countries:
# Analyze debt composition by major creditors
creditor_analysis <- ids_get(
geographies = c("AGO", "BWA", "BDI", "CMR", "CPV", "CAF", "TCD", "COM", "COG", "COD",
"BEN", "ETH", "GAB", "GMB", "GHA", "GIN", "GNB", "GNQ", "CIV", "KEN",
"LSO", "LBR", "MDG", "MWI", "MLI", "MRT", "MUS", "MOZ", "NER", "NGA",
"REU", "ZWE", "RWA", "STP", "SEN", "SYC", "ERI", "SLE", "SOM", "DJI",
"NAM", "SDN", "SWZ", "TZA", "TGO", "UGA", "BFA", "ZMB"), # SSA countries
series = c(
"DT.DOD.DECT.CD" # Total external debt
),
counterparts = c(
"WLD", # World total
"730", # China
"302", # USA
"004", # France
"005", # Germany
"012", # UK
"006", # Italy
"050" # Spain
),
start_year = 2000
)
# Export the data on Excel
write_xlsx(creditor_analysis, path = "creditor_analysis.xlsx")
##############################################################################
# Analyze debt composition by major creditors
creditor_analysis1 <- ids_get(
geographies = c("AGO", "BWA", "BDI", "CMR", "CPV", "CAF", "TCD", "COM", "COG", "COD",
"BEN", "ETH", "GAB", "GMB", "GHA", "GIN", "GNB", "GNQ", "CIV", "KEN",
"LSO", "LBR", "MDG", "MWI", "MLI", "MRT", "MUS", "MOZ", "NER", "NGA",
"REU", "ZWE", "RWA", "STP", "SEN", "SYC", "ERI", "SLE", "SOM", "DJI",
"NAM", "SDN", "SWZ", "TZA", "TGO", "UGA", "BFA", "ZMB"), # SSA countries
series = c(
"DT.TDS.DECT.CD" # Total debt service
),
counterparts = c(
"WLD", # World total
"730", # China
"302", # USA
"004", # France
"005", # Germany
"012", # UK
"006", # Italy
"050" # Spain
),
start_year = 2000
)
# Export the data on Excel
write_xlsx(creditor_analysis1, path = "creditor_analysis1.xlsx")
################################################################################
# Analyze debt composition by major creditors
creditor_analysis2 <- ids_get(
geographies = c("AGO", "BWA", "BDI", "CMR", "CPV", "CAF", "TCD", "COM", "COG", "COD",
"BEN", "ETH", "GAB", "GMB", "GHA", "GIN", "GNB", "GNQ", "CIV", "KEN",
"LSO", "LBR", "MDG", "MWI", "MLI", "MRT", "MUS", "MOZ", "NER", "NGA",
"REU", "ZWE", "RWA", "STP", "SEN", "SYC", "ERI", "SLE", "SOM", "DJI",
"NAM", "SDN", "SWZ", "TZA", "TGO", "UGA", "BFA", "ZMB"), # SSA countries
series = c(
"DT.DOD.BLAT.CD" # PPG, bilateral (DOD, current US$)
),
counterparts = c(
"WLD", # World total
"730", # China
"302", # USA
"004", # France
"005", # Germany
"012", # UK
"006", # Italy
"050" # Spain
),
start_year = 2000
)
# Export the data on Excel
write_xlsx(creditor_analysis2, path = "creditor_analysis2.xlsx")
################################################################################
