downloading data from OECD website using the OECD package in R

Viewed 767

I am trying to download data directly from the OECD website using the OECD package in R. I'm specifically trying to download data from the industrial production dataset (https://data.oecd.org/industry/industrial-production.htm) for South Africa. I believe that the codes for the dataset itself and for South Africa are MEI_REAL and ZAF.

However, when I try to run the following

df <- get_dataset("MEI_REAL",
                  filter = 'ZAF',
                  start_time = 2019, end_time = 2020)

I get the following error

Error in rsdmx::readSDMX(url) : 
  HTTP request failed with status: 400 Bad Request

Can anyone advise on what I'm doing wrong? I've never used this package before so I'm struggling to figure it out.

TIA

3 Answers

To actually use the filter it has to be something like

df <- get_dataset("MEI_REAL",
                  filter = list(c(),'ZAF'),
                  start_time = 2019, end_time = 2020)

as the country codes are in the second column, but I don't know how you can know this in advance without just downloading the whole dataset first (just drop the filter argument entirely to do that).

The code in the question fails because LOCATION is the second column in the data frame, and the filter = statement does not account for this. We can fix the request by adding NULL to the list() passed to filter= argument.

library(OECD)

# filter on second column
saProduction <- get_dataset("MEI_REAL",
                            filter = list(NULL,"ZAF"),
                            start_time = 2019,
                            end_time = 2020)

head(saProduction)

...and the output:

> head(saProduction)
   SUBJECT LOCATION FREQUENCY TIME_FORMAT UNIT POWERCODE REFERENCEPERIOD obsTime
1 PRMNTO01      ZAF         A         P1Y  IDX         0        2015_100    2019
2 PRMNTO01      ZAF         Q         P3M  IDX         0        2015_100 2019-Q1
3 PRMNTO01      ZAF         Q         P3M  IDX         0        2015_100 2019-Q2
4 PRMNTO01      ZAF         Q         P3M  IDX         0        2015_100 2019-Q3
5 PRMNTO01      ZAF         Q         P3M  IDX         0        2015_100 2019-Q4
6 PRMNTO01      ZAF         Q         P3M  IDX         0        2015_100 2020-Q1
   obsValue
1 100.46670
2 100.97510
3 101.30840
4 100.04170
5  99.47495
6  97.40812 

How did I figure out that the right entry into the list is NULL? When one looks at the arguments for get_dataset(), we see that NULL is a valid value for filter =, so I inferred that I could use it as a value in the filter list().

For anyone who ecnounters the same problem: My "solution" is to set the dataframe-ID you want at different positions in the filter. E.g: 1.try:

filter_GDP <- list("B1_GE")
GDP <- get_dataset("QNA", filter_GDP)

This gives back an error, hence i set the dataframe-ID at the next position in the filter list (by including NULL):

filter_GDP <- list(NULL, "B1_GE")
GDP <- get_dataset("QNA", filter_GDP)

This works, so now you can look up the positions of the other parameters you want to filter, in my case:

filter_GDP <- list(NULL,"B1_GE", "CQRSA", "Q")
GDP <- get_dataset("QNA", filter_GDP)
Related