HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Pulling OECD data into R #17

Open oliverbott opened 9 years ago

oliverbott commented 9 years ago

Hello everyone, if you want to use OECD data for your project, I recommend getting the "rsdmx" package for R. This link is very helpful: https://github.com/opensdmx/rsdmx/wiki#package_status

Installing the package

These are the codes I used to get the rsdmx package running in R.

install.packages("devtools")
require("devtools")
install_github("rsdmx", "opensdmx")
library("rsdmx")

Getting the SMDX link

Once you opened the OECD statistics you are interested in, you click on EXPORT and choose SDMX. Copy the SDMX DATA URL. It will look something like this:

http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/CITIES/DEU+DE001+DE002+DE003+DE004+DE005+DE006+DE007+DE008+DE009+DE010+DE011+DE012+DE013+DE014+DE015+DE027+DE033+DE034+DE035+DE040+DE501+DE502+DE504+DE507.PCT_INTENSITY?startTime=2000&endTime=2012

Turning SDMX file into a table

With these codes you turn the SDMX data into a nice data frame ready for tidying up.

dataURL <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/CITIES/DEU+DE001+DE002+DE003+DE004+DE005+DE006+DE007+DE008+DE009+DE010+DE011+DE012+DE013+DE014+DE015+DE027+DE033+DE034+DE035+DE040+DE501+DE502+DE504+DE507.PCT_INTENSITY?startTime=2000&endTime=2012"

sdmx <- readSDMX(dataURL)
stats <- as.data.frame(sdmx)

I hope this helps.

christophergandrud commented 9 years ago

That's great. Thanks for sharing. (I just made some minor formatting edits).