The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Using GetQuandlData to study inflation rates around the world

Marcelo Perlin

2023-02-15

Quandl is one of the best platforms for finding and downloading financial and economic time series. The collection of free databases is comprehensive and I’ve used it intensively in my research and class material.

But, a couple of things from the native package Quandl always bothered me:

As you suspect, I decided to tackle the problem over the weekend. The result is package GetQuandlData. This is what it does differently:

Installation

# not in CRAN yet (need to test it further)
#install.packages('GetQuandlData')

# from github
devtools::install_github('msperlin/GetQuandlData')

Example 01 - Inflation in the US

Let’s download and plot information about inflation in the US:

library(GetQuandlData)

my_id <- c('Inflation USA' = 'RATEINF/INFLATION_USA')
my_api <- readLines('YOURAPIHERE') # you need your own API (get it at https://www.quandl.com/sign-up-modal?defaultModal=showSignUp>)
first_date <- '2000-01-01'
last_date <- Sys.Date()

df <- get_Quandl_series(id_in = my_id, 
                        api_key = my_api, 
                        first_date = first_date,
                        last_date = last_date, 
                        cache_folder = tempdir())

dplyr::glimpse(df)

As you can see, the data is in the long format. Let’s plot it:

p <- ggplot(df, aes(x = ref_date, y = value/100)) + 
  geom_col() + 
  labs(y = 'Inflation (%)', 
       x = '',
       title = 'Inflation in the US') + 
  scale_y_continuous(labels = scales::percent)

p

Beautiful!

Example 02 - Inflation for many countries

Next, lets have a look into a more realistic case, where we need inflation data for several countries:

First, we need to see what are the available datasets from database RATEINF:

library(GetQuandlData)

db_id <- 'RATEINF'
my_api <- readLines('YOURAPIHERE') # you need your own API

df <- get_database_info(db_id, my_api)

head(df)

Nice. Now we only need to filter the series with YOY inflation:

idx <- stringr::str_detect(df$name, 'Inflation YOY')

df_series <- df[idx, ]

and grab the data:

my_id <- df_series$quandl_code
names(my_id) <- df_series$name
first_date <- '2010-01-01'
last_date <- Sys.Date()

df_inflation <- get_Quandl_series(id_in = my_id, 
                                  api_key = my_api,
                                  first_date = first_date,
                                  last_date = last_date,
                                  cache_folder = tempdir())

glimpse(df_inflation)

And, an elegant plot:

p <- ggplot(df_inflation, aes(x = ref_date, y = value/100)) + 
  geom_col() + 
  labs(y = 'Inflation (%)', 
       x = '',
       title = 'Inflation in the World',
       subtitle = paste0(first_date, ' to ', last_date)) + 
  scale_y_continuous(labels = scales::percent) + 
  facet_wrap(~series_name)

p

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.