World Development Indicators and Other World Bank Data

Search and download data from over 40 databases hosted by the World Bank, including the World Development Indicators ('WDI'), International Debt Statistics, Doing Business, Human Capital Index, and Sub-national Poverty indicators.


The World Bank makes available a ton of great data from the World Development Indicators through its web API. The WDI package for R makes it easy to search and download data series from the WDI.

Installation

WDI is published on CRAN and so can be installed by simply typing this in the R console:

install.packages('WDI')

Searching for data

You can search for data by using keywords in WDIsearch. For instance, if you are looking for data on Gross Domestic Product:

WDIsearch('gdp')

Which produces this:

      indicator              name                                                                      
 [1,] "BG.GSR.NFSV.GD.ZS"    "Trade in services (% of GDP)"                                            
 [2,] "BM.KLT.DINV.GD.ZS"    "Foreign direct investment, net outflows (% of GDP)"                      
 [3,] "BN.CAB.XOKA.GD.ZS"    "Current account balance (% of GDP)"                                      
 [4,] "BN.CUR.GDPM.ZS"       "Current account balance excluding net official capital grants (% of GDP)"
 [5,] "BN.GSR.FCTY.CD.ZS"    "Net income (% of GDP)"                                                   
 [6,] "BN.KLT.DINV.CD.ZS"    "Foreign direct investment (% of GDP)"                                    
 [7,] "BN.KLT.PRVT.GD.ZS"    "Private capital flows, total (% of GDP)"                                 
 [8,] "BN.TRF.CURR.CD.ZS"    "Net current transfers (% of GDP)"                                        
 [9,] "BNCABFUNDCD_"         "Current Account Balance, %GDP"                                           
[10,] "BX.KLT.DINV.WD.GD.ZS" "Foreign direct investment, net inflows (% of GDP)" 

WDIsearch uses grep and ignores cases, so you can also use regular expressions. For instance, if you are looking for GDP per capita in constant dollars:

WDIsearch('gdp.*capita.*constant')
     indicator           name                                                 
[1,] "GDPPCKD"           "GDP per Capita, constant US$, millions"             
[2,] "NY.GDP.PCAP.KD"    "GDP per capita (constant 2000 US$)"                 
[3,] "NY.GDP.PCAP.KN"    "GDP per capita (constant LCU)"                      
[4,] "NY.GDP.PCAP.PP.KD" "GDP per capita, PPP (constant 2005 international $)"

Download and use the data

Download a series you like for the countries you like:

dat = WDI(indicator='NY.GDP.PCAP.KD', country=c('MX','CA','US'), start=1960, end=2012)

Look at the data:

head(dat)
  iso2c country NY.GDP.PCAP.KD year
1    CA  Canada       9374.883 1960
2    CA  Canada       9479.824 1961
3    CA  Canada       9967.366 1962
4    CA  Canada      10290.362 1963
5    CA  Canada      10774.653 1964
6    CA  Canada      11283.606 1965

Plot the data:

library(ggplot2)
ggplot(dat, aes(year, NY.GDP.PCAP.KD, color=country)) + geom_line() + 
    xlab('Year') + ylab('GDP per capita')

GDP per capita in North America

Note: You can use country='all' to download data for all available countries. You can also feed a vector of indicator strings if you want to download multiple indicators at once.

Updating series list

To speed up search, WDI ships with a local list of all available WDI series as of 2012-06-18. This list will be updated semi-regularly, but you may still want to update it manually to get access to the very latest data series. To do so, use the cache function:

new_cache = WDIcache()
WDIsearch('gdp', cache=new_cache)

Bugs, suggestions, etc.

Thanks for using WDI! Please send all bug reports and suggestions through the github issue tracker or by email at [email protected]

News

Version 2.6.0 (2019-03-02)

  • start and end are NULL as default and download all available years.
  • label attribute to the return data.frame includes descriptive labels for each
  • WDIbulk function to download all of WDI
  • WDIcache and data trim whitespace from region names

Version 2.5.1 (2018-12-05)

  • New version numbering scheme
  • Updated country and indicator data

Version 2.5.0 (2018-04-09)

  • Namespace issues (thanks to Jan Dietrich)
  • Updated the list of available indicators
  • Allow iso3c or iso2c as input for country argument
  • Rolled-back indicator input clean up because too aggressive (Thanks to Geoff Wright)
  • Rename columns automatically when using a named vector

Version 2.4.0

  • Call RJSONIO::fromJSON explicitly to avoid conflict with JSON package (Thanks to Richard Cotton)

Version 2.3.0

  • Change default start/end date per user request

Version 2.2.0

  • Bug: country names were stripped of digits

Version 2.1.0

  • Fixed various issues (thanks to Matthieu Stigler for bug reports and patches)
  • Faster downloads when requesting multiple countries (leveraging the US;BR;CA API syntax)

Version 2.0.0

  • Now uses JSON instead of XML (Faster, easier)
  • WDIcache function now allows users to update the locally stored database of available WDI series
  • Fixed doc examples
  • Documentation now uses roxygen2
  • Moved development to github
  • Series and country info now in a single data list. utf-8 encoding fixed

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("WDI")

2.7.1 by Vincent Arel-Bundock, 4 months ago


https://vincentarelbundock.github.io/WDI


Browse source code at https://github.com/cran/WDI


Authors: Vincent Arel-Bundock <[email protected]>


Documentation:   PDF Manual  


Task views:


GPL-3 license


Imports RJSONIO

Suggests tidyr, testthat


Imported by ITNr, choroplethr.


See at CRAN