Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imf_data doesn't return commodity data #34

Open
alexcaldarone opened this issue Jul 8, 2021 · 3 comments
Open

imf_data doesn't return commodity data #34

alexcaldarone opened this issue Jul 8, 2021 · 3 comments

Comments

@alexcaldarone
Copy link

alexcaldarone commented Jul 8, 2021

When I try to retrieve commodity prices with the imf_data function it returns an error saying that the data was not found, even though I specify all the arguments the function requires and the indicator exists in the IMF data portal.
How can I solve this issue?

copper <- imf_data( database_id = 'PCPS', indicator = 'PCOPP', freq = 'M', return_raw = FALSE )
Error: No data found.

I have also tried changing the frequency values but i still get the same error.
Thank you.

@GuilhermeStipp
Copy link

I have the same problem. I saw that this question has been open for months and no one has responded. Did you manage to find the solution elsewhere @alexcaldarone?

@cjyetman
Copy link
Contributor

I think this is probably a problem with IMF. Even if you download the full PCPS dataset it does not include data for the indicator "PCOPP"...

library(httr)
library(jsonlite)

url <- "http://dataservices.imf.org/REST/SDMX_JSON.svc/CompactData/PCPS/"
raw_data <-
  httr::RETRY("GET", url, user_agent(""), progress(), times = 3) %>% 
  httr::content(type = "text", encoding = "UTF-8") %>% 
  jsonlite::fromJSON()

data <- 
  raw_data$CompactData$DataSet$Series %>% 
  unnest(Obs)

sort(unique(data$`@COMMODITY`))
#>  [1] "PAGRI"    "PALLFNF"  "PALLMETA" "PBEVE"    "PCOAL"    "PEXGALL" 
#>  [7] "PEXGMETA" "PFANDB"   "PFERT"    "PFOOD"    "PINDU"    "PMETA"   
#> [13] "PNFUEL"   "PNGAS"    "PNRG"     "POILAPSP" "PPMETA"   "PRAWM"

even though the metadata says that "PCOPP" is a valid indicator name (which it may be, even if there is currently no data for it)...

library(tidyverse)
library(imfr)

imf_codes(codelist = "CL_INDICATOR_PCPS") %>% 
  filter(grepl("copper", description, ignore.case = TRUE))
#>     codes                       description
#>  1 PCOPP Primary Commodity Prices, Copper 

@cjyetman
Copy link
Contributor

An additional relevant note, though this does not solve the problem that the IMF API does not have/return any data for the indicator PCOPP in the database_id PCPS...

Since the PCPS data only appears to contain data points tagged with the regional code W00, it is necessary to specify that in the country parameter of imf_data()...

library(imfr)

database_id <- "PCPS"

imf_codelist(database_id = database_id)
#>            codelist        description
#> 1      CL_UNIT_MULT              Scale
#> 2           CL_FREQ          Frequency
#> 3      CL_AREA_PCPS Geographical Areas
#> 4 CL_INDICATOR_PCPS          Indicator
#> 5      CL_UNIT_PCPS               Unit
#> 6    CL_TIME_FORMAT        Time format

imf_codes(codelist = "CL_AREA_PCPS")
#>   codes                     description
#> 1   W00 All Countries, excluding the IO

imf_data(database_id = "PCPS", indicator = "PRAWM")
#> Error: No data found.

imf_data(database_id = "PCPS", indicator = "PRAWM", country = "W00")
#>    iso2c year        PRAWM
#> 1    W00 2000  73.27785169
#> 2    W00 2001  65.91463699
#> 3    W00 2002  67.89649128
#> 4    W00 2003  78.21653651
#> 5    W00 2004  84.31019783
#> 6    W00 2005  86.86112189
#> 7    W00 2006  99.01736501
#> 8    W00 2007 104.20925058
#> 9    W00 2008 110.28165904
#> 10   W00 2009  96.09214895
#> 11   W00 2010 129.57285500
#> 12   W00 2011 161.03030418
#> 13   W00 2012 127.93862588
#> 14   W00 2013 122.26496101
#> 15   W00 2014 113.07284895
#> 16   W00 2015 100.01964075
#> 17   W00 2016 100.00000000
#> 18   W00 2017 105.24498006
#> 19   W00 2018 107.34384032
#> 20   W00 2019 101.52730642
#> 21   W00 2020  98.15826604
#> 22   W00 2021 113.67881613
#> 23   W00 2000   3.15886226
#> 24   W00 2001 -10.04834957
#> 25   W00 2002   3.00669833
#> 26   W00 2003  15.19967385
#> 27   W00 2004   7.79075831
#> 28   W00 2005   3.02564118
#> 29   W00 2006  13.99503351
#> 30   W00 2007   5.24340915
#> 31   W00 2008   5.82712996
#> 32   W00 2009 -12.86660920
#> 33   W00 2010  34.84229088
#> 34   W00 2011  24.27780817
#> 35   W00 2012 -20.54996944
#> 36   W00 2013  -4.43467704
#> 37   W00 2014  -7.51819000
#> 38   W00 2015 -11.54406944
#> 39   W00 2016  -0.01963689
#> 40   W00 2017   5.24498006
#> 41   W00 2018   1.99426164
#> 42   W00 2019  -5.41860053
#> 43   W00 2020  -3.31835887
#> 44   W00 2021  15.81176066
#> 45   W00 2000   3.15886226
#> 46   W00 2001 -10.04834957
#> 47   W00 2002   3.00669833
#> 48   W00 2003  15.19967385
#> 49   W00 2004   7.79075831
#> 50   W00 2005   3.02564118
#> 51   W00 2006  13.99503351
#> 52   W00 2007   5.24340915
#> 53   W00 2008   5.82712996
#> 54   W00 2009 -12.86660920
#> 55   W00 2010  34.84229088
#> 56   W00 2011  24.27780817
#> 57   W00 2012 -20.54996944
#> 58   W00 2013  -4.43467704
#> 59   W00 2014  -7.51819000
#> 60   W00 2015 -11.54406944
#> 61   W00 2016  -0.01963689
#> 62   W00 2017   5.24498006
#> 63   W00 2018   1.99426164
#> 64   W00 2019  -5.41860053
#> 65   W00 2020  -3.31835887
#> 66   W00 2021  15.81176066

Created on 2022-02-20 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants