• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    R
  • Created over 12 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

R package to download World Bank data

World Bank data in R

The WDI package allows users to search and download data from over 40 datasets hosted by the World Bank, including the World Development Indicators ('WDI'), International Debt Statistics, Doing Business, Human Capital Index, and Sub-national Poverty indicators.

CRAN downloads AppVeyor build status R build status

Installation

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

install.packages('WDI')

To install the development version of the package, use remotes:

library(remotes)
install_github('vincentarelbundock/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:

> WDIsearch('gdp')[1:10,]
      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.

Monthly or quarterly data

Some World Bank series are available at the monthly or quarterly frequency. You can download those simply using the start and end arguments:

WDI(indicator = 'DPANUSSPB', country = 'CHN', start = '2012M01', end = '2012M05')

  iso2c country DPANUSSPB    year
1   CHN   China  6.324130 2012M05
2   CHN   China  6.303810 2012M04
3   CHN   China  6.313545 2012M03
4   CHN   China  6.300286 2012M02
5   CHN   China  6.313091 2012M01

Automatic rename

If the vector that you supply to WDI is named, the function will automatically rename columns where possible.

dat <- WDI(indicator = c("gdp_per_capita" = "NY.GDP.PCAP.KD",
                         "population" = "SP.POP.TOTL"))
head(dat)
iso2c    country year gdp_per_capita population
1    1A Arab World 2005       5378.379  316264728
2    1A Arab World 2006       5594.899  323773264
3    1A Arab World 2007       5711.663  331653797
4    1A Arab World 2008       5898.516  339825483
5    1A Arab World 2009       5782.422  348145094
6    1A Arab World 2010       5916.330  356508908

Updating series list

To speed up search, WDI ships with a local list of all available WDI series. 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 to [email protected]

More Repositories

1

modelsummary

Beautiful and customizable model summaries in R.
R
778
star
2

countrycode

R package: Convert country names and country codes. Assigns region descriptors.
R
343
star
3

marginaleffects

R package to compute and plot predictions, slopes, marginal means, and comparisons (contrasts, risk ratios, odds, etc.) for over 80 classes of statistical models. Conduct linear and non-linear hypothesis tests, or equivalence tests. Calculate uncertainty estimates using the delta method, bootstrapping, or simulation-based inference.
R
290
star
4

Rdatasets

A collection of datasets originally distributed in R packages
HTML
242
star
5

rethinking2

HTML
69
star
6

pymarginaleffects

Python
47
star
7

Reinhart-Rogoff

Reinhart Rogoff replication files: Python stats with IPython notebook
Python
28
star
8

softbib

Software Bibliographies for R Projects
R
24
star
9

marginsplot

plot marginal effects and predicted values using the `margins` and `ggplot2` libraries for `R`
R
9
star
10

tinysnapshot

Snapshots for unit tests using the tinytest framework for `R`. Includes expectations to test base `R` and `ggplot2` plots as well as console output from `print()`.
R
9
star
11

ACMQ

Analyse Causale et Mรฉthodes Quantitatives
CSS
8
star
12

violets

Violets are BLUE. OLS is too. (R package)
R
8
star
13

opic

Overseas Private Investment Corporation data on projects and insurance claims
R
7
star
14

SpatialHelper

A collection of helper functions for network analysis (TERGM) and spatial econometrics in R
R
4
star
15

modelarchive

Archive of `R` models used to test `{modelsummary}` and `{marginaleffects}`
2
star
16

pycountrycode

Python
2
star
17

regrets

R package to print facts and pictures of egrets
R
1
star
18

vincentarelbundock.github.io

Vincent's projects
CSS
1
star