World Bank Development indicators for R

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.

See package details at: https://github.com/vincentarelbundock/WDI

library(WDI)
## Loading required package: RJSONIO
search <- WDIsearch('gdp')
search[1:10,]
##       indicator             
##  [1,] "BG.GSR.NFSV.GD.ZS"   
##  [2,] "BM.KLT.DINV.GD.ZS"   
##  [3,] "BN.CAB.XOKA.GD.ZS"   
##  [4,] "BN.CUR.GDPM.ZS"      
##  [5,] "BN.GSR.FCTY.CD.ZS"   
##  [6,] "BN.KLT.DINV.CD.ZS"   
##  [7,] "BN.KLT.PRVT.GD.ZS"   
##  [8,] "BN.TRF.CURR.CD.ZS"   
##  [9,] "BNCABFUNDCD_"        
## [10,] "BX.KLT.DINV.WD.GD.ZS"
##       name                                                                      
##  [1,] "Trade in services (% of GDP)"                                            
##  [2,] "Foreign direct investment, net outflows (% of GDP)"                      
##  [3,] "Current account balance (% of GDP)"                                      
##  [4,] "Current account balance excluding net official capital grants (% of GDP)"
##  [5,] "Net income (% of GDP)"                                                   
##  [6,] "Foreign direct investment (% of GDP)"                                    
##  [7,] "Private capital flows, total (% of GDP)"                                 
##  [8,] "Net current transfers (% of GDP)"                                        
##  [9,] "Current Account Balance, %GDP"                                           
## [10,] "Foreign direct investment, net inflows (% of GDP)"
# Download and use data
dat = WDI(indicator='NY.GDP.PCAP.KD', country=c('MX','CA','US'), start=1960, end=2012)
head(dat)
##   iso2c country NY.GDP.PCAP.KD year
## 1    CA  Canada          35992 2012
## 2    CA  Canada          35794 2011
## 3    CA  Canada          35277 2010
## 4    CA  Canada          34583 2009
## 5    CA  Canada          36006 2008
## 6    CA  Canada          36183 2007
library(ggplot2)
ggplot(dat, aes(year, NY.GDP.PCAP.KD, color=country)) + geom_line() +  xlab('Year') + ylab('GDP per capita')

plot of chunk unnamed-chunk-3

# Searching GDP indicators of Spain
# Seach gdp indicators
gdp <- WDIsearch('gdp')
gdp[1:20,]
##       indicator             
##  [1,] "BG.GSR.NFSV.GD.ZS"   
##  [2,] "BM.KLT.DINV.GD.ZS"   
##  [3,] "BN.CAB.XOKA.GD.ZS"   
##  [4,] "BN.CUR.GDPM.ZS"      
##  [5,] "BN.GSR.FCTY.CD.ZS"   
##  [6,] "BN.KLT.DINV.CD.ZS"   
##  [7,] "BN.KLT.PRVT.GD.ZS"   
##  [8,] "BN.TRF.CURR.CD.ZS"   
##  [9,] "BNCABFUNDCD_"        
## [10,] "BX.KLT.DINV.WD.GD.ZS"
## [11,] "BX.TRF.MGR.DT.GD.ZS" 
## [12,] "BX.TRF.PWKR.DT.GD.ZS"
## [13,] "BX.TRF.PWKR.GD.ZS"   
## [14,] "CM.MKT.LCAP.GD.ZS"   
## [15,] "CM.MKT.TRAD.GD.ZS"   
## [16,] "DT.DOD.ALLC.ZSG"     
## [17,] "DT.DOD.ALLN.ZSG"     
## [18,] "DT.DOD.DECT.CD.ZSG"  
## [19,] "DT.ODA.ALLD.GD.ZS"   
## [20,] "DT.ODA.DACD.ZSG"     
##       name                                                                      
##  [1,] "Trade in services (% of GDP)"                                            
##  [2,] "Foreign direct investment, net outflows (% of GDP)"                      
##  [3,] "Current account balance (% of GDP)"                                      
##  [4,] "Current account balance excluding net official capital grants (% of GDP)"
##  [5,] "Net income (% of GDP)"                                                   
##  [6,] "Foreign direct investment (% of GDP)"                                    
##  [7,] "Private capital flows, total (% of GDP)"                                 
##  [8,] "Net current transfers (% of GDP)"                                        
##  [9,] "Current Account Balance, %GDP"                                           
## [10,] "Foreign direct investment, net inflows (% of GDP)"                       
## [11,] "Migrant remittance inflows (% of GDP)"                                   
## [12,] "Workers' remittances and compensation of employees, received (% of GDP)" 
## [13,] "Workers' remittances, receipts (% of GDP)"                               
## [14,] "Market capitalization of listed companies (% of GDP)"                    
## [15,] "Stocks traded, total value (% of GDP)"                                   
## [16,] "Debt on Concessional terms to GDP (% of GDP)"                            
## [17,] "Debt on Non-concessional terms to GDP (% of GDP)"                        
## [18,] "Debt outstanding and disbursed, Total to GDP (% of GDP)"                 
## [19,] "Net ODA received (% of GDP)"                                             
## [20,] "Net ODA received from DAC donors (% of recipient's GDP)"
# Download gdp indicators
# Trade in services (% of GDP)
trade = WDI(indicator='BG.GSR.NFSV.GD.ZS', country='ES', start=2005, end=2012)
head(trade)
##   iso2c country BG.GSR.NFSV.GD.ZS year
## 1    ES   Spain             17.16 2012
## 2    ES   Spain             16.44 2011
## 3    ES   Spain             15.41 2010
## 4    ES   Spain             14.62 2009
## 5    ES   Spain             15.74 2008
## 6    ES   Spain             15.71 2007
ggplot(trade, aes(year, BG.GSR.NFSV.GD.ZS)) + geom_line() +  xlab('Year') + ylab('Trade in services (% of GDP)')

plot of chunk unnamed-chunk-6

# Foreign direct investment, net outflows (% of GDP)
# BM.KLT.DINV.GD.ZS
foreign = WDI(indicator='BM.KLT.DINV.GD.ZS', country='ES', start=2005, end=2012)
head(foreign)
##   iso2c country BM.KLT.DINV.GD.ZS year
## 1    ES   Spain            0.3579 2012
## 2    ES   Spain            2.9143 2011
## 3    ES   Spain            3.0601 2010
## 4    ES   Spain            1.4994 2009
## 5    ES   Spain            4.6415 2008
## 6    ES   Spain           10.8403 2007
ggplot(foreign, aes(year, BM.KLT.DINV.GD.ZS)) + geom_line() +  xlab('Year') + ylab('Foreign direct investment, net outflows (% of GDP)')

plot of chunk unnamed-chunk-8

# Stocks traded, total value (% of GDP)
# CM.MKT.TRAD.GD.ZS
stocks = WDI(indicator='CM.MKT.TRAD.GD.ZS', country='ES', start=2005, end=2012)
head(stocks)
##   iso2c country CM.MKT.TRAD.GD.ZS year
## 1    ES   Spain             81.41 2012
## 2    ES   Spain             97.66 2011
## 3    ES   Spain             98.92 2010
## 4    ES   Spain            109.97 2009
## 5    ES   Spain            153.14 2008
## 6    ES   Spain            205.50 2007
ggplot(stocks, aes(year, CM.MKT.TRAD.GD.ZS)) + geom_line() +  xlab('Year') + ylab('Stocks traded, total value (% of GDP)')

plot of chunk unnamed-chunk-10