Macroeconomic Observatory - R, and kindly contributed to Want to share your content on R-bloggers? [This article was first published on, and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

DBnomics : the world’s economic database

Explore all the economic data from different providers (national and international statistical institutes, central banks, etc.), for free, following the link db.nomics.world.

You can also retrieve all the economic data through the rdbnomics package here. This blog post describes the different ways to do so.

Fetch time series by ids

First, let’s assume that we know which series we want to download. A series identifier ( ids ) is defined by three values, formatted like this: provider_code / dataset_code / series_code .

Fetch one series from dataset ‘Unemployment rate’ ( ZUTN ) of AMECO provider

library(magrittr) library(dplyr) library(ggplot2) library(rdbnomics) df % filter(!is.na(value))

In such data.frame (data.table or tibble), you will always find at least nine columns:

provider_code

dataset_code

dataset_name

series_code

series_name

original_period (character string)

(character string) period (date of the first day of original_period )

(date of the first day of ) original_value (character string)

(character string) value

@frequency (harmonized frequency generated by DBnomics)

The other columns depend on the provider and on the dataset. They always come in pairs (for the code and the name). In the data.frame df , you have:

unit (code) and Unit (name)

(code) and (name) geo (code) and Country (name)

(code) and (name) freq (code) and Frequency (name)

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

In the event that you only use the argument ids , you can drop it and run:

Fetch two series from dataset ‘Unemployment rate’ ( ZUTN ) of AMECO provider

df % filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

Fetch two series from different datasets of different providers

df % filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics() + theme(legend.text = element_text(size=7))

Fetch time series by mask

The code mask notation is a very concise way to select one or many time series at once. It is compatible only with some providers : BIS, ECB, Eurostat, FED, ILO, IMF, INSEE, OECD, WTO.

Fetch one series from dataset ‘Balance of Payments’ ( BOP ) of IMF

df % filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

In the event that you only use the arguments provider_code , dataset_code and mask , you can drop the name mask and run:

Fetch two series from dataset ‘Balance of Payments’ ( BOP ) of IMF

You just have to add a + between two different values of a dimension.

df % filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

Fetch all series along one dimension from dataset ‘Balance of Payments’ ( BOP ) of IMF

df % filter(!is.na(value)) %>% arrange(desc(period), REF_AREA) %>% head(100)

Fetch series along multiple dimensions from dataset ‘Balance of Payments’ ( BOP ) of IMF

df % filter(!is.na(value)) %>% group_by(INDICATOR) %>% top_n(n = 50, wt = period)

Fetch time series by dimensions

Searching by dimensions is a less concise way to select time series than using the code mask , but it works with all the different providers. You have a “Description of series code” at the bottom of each dataset page on the DBnomics website.

Fetch one value of one dimension from dataset ‘Unemployment rate’ ( ZUTN ) of AMECO provider

df % filter(!is.na(value)) # or # df % # filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

Fetch two values of one dimension from dataset ‘Unemployment rate’ ( ZUTN ) of AMECO provider

df % filter(!is.na(value)) # or # df % # filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

Fetch several values of several dimensions from dataset ‘Doing business’ ( DB ) of World Bank

df % filter(!is.na(value)) # or # df % # filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

Fetch time series found on the web site

When you don’t know the codes of the dimensions, provider, dataset or series, you can:

go to the page of a dataset on DBnomics website, for example Doing Business,

select some dimensions by using the input widgets of the left column,



click on “Copy API link” in the menu of the “Download” button,



use the rdb_by_api_link function such as below.

df % filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_step(size = 1.2) + geom_point(size = 2) + dbnomics()

Fetch time series from the cart

On the cart page of the DBnomics website, click on “Copy API link” and copy-paste it as an argument of the rdb_by_api_link function. Please note that when you update your cart, you have to copy this link again, because the link itself contains the ids of the series in the cart.









df % filter(!is.na(value))

ggplot(df, aes(x = period, y = value, color = series_name)) + geom_line(size = 1.2) + geom_point(size = 2) + dbnomics()

Proxy configuration or connection error Could not resolve host

When using the functions rdb or rdb_... , you may come across the following error:

Error in open.connection(con, "rb") : Could not resolve host: api.db.nomics.world

To get round this situation, you have two options:

configure curl to use a specific and authorized proxy. use the default R internet connection i.e. the Internet Explorer proxy defined in internet2.dll.

Configure curl to use a specific and authorized proxy

In rdbnomics, by default the function curl_fetch_memory (of the package curl) is used to fetch the data. If a specific proxy must be used, it is possible to define it permanently with the package option rdbnomics.curl_config or on the fly through the argument curl_config . Because the object is a named list, its elements are passed to the connection (the curl_handle object created internally with new_handle() ) with handle_setopt() before using curl_fetch_memory .

To see the available parameters, run names(curl_options()) in R or visit the website https://curl.haxx.se/libcurl/c/curl_easy_setopt.html. Once they are chosen, you define the curl object as follows:

h ", proxyport = , proxyusername = " ", proxypassword = " " )

Set the connection up for a session

The curl connection can be set up for a session by modifying the following package option:

options(rdbnomics.curl_config = h)

When fetching the data, the following command is executed:

hndl , handle = hndl)

After configuration, just use the standard functions of rdbnomics e.g.: