13  Using Data From WDI

13.1 Background

The World Bank collects statistical information from countries around the world. A particularly useful data set is the World Development Indicators (WDI) which are country level statistical information from around the world.

Using library(WDI) you can download indicator data directly from the World Bank and read it into a data set.

13.2 Call Libraries

Show the code
library(WDI) # for accessing World Bank data

library(dplyr) # data wrangling

13.3 Get Some Data From the World Development Indicators (WDI)

Show the code
# get names of specific indicators from WDI Data Catalog

WorldBankData <- WDI(country="all", 
                     indicator=c("SI.POV.GINI", # Gini
                                 "NY.GDP.PCAP.CD", # GDP
                                 "SE.ADT.LITR.ZS", # adult literacy
                                 "SP.DYN.LE00.IN", # life expectancy
                                 "SP.POP.TOTL", # population
                                 "SN.ITK.DEFC.ZS"), # undernourishment
                     start = 2023, 
                     end = 2023, 
                     extra = TRUE) 


save(WorldBankData, file="WorldBankData.RData")

14 Rename Some Variables

Show the code
# think about renaming some variables with more intuitive names
# e.g....

# rename some variables with dplyr (just copy and paste your indicators)

WorldBankData <- dplyr::rename(WorldBankData, 
                        GDP = NY.GDP.PCAP.CD,
                        adult_literacy = SE.ADT.LITR.ZS,
                        life_expectancy = SP.DYN.LE00.IN, 
                        population = SP.POP.TOTL,
                        Gini = SI.POV.GINI,
                        undernourishment = SN.ITK.DEFC.ZS)

save(WorldBankData, file="WorldBankData.RData")

14.1 Look At The Data

Show the code
load("WorldBankData.RData") # load the data

head(WorldBankData)
                      country iso2c iso3c year status lastupdated Gini      GDP
1                 Afghanistan    AF   AFG 2023         2024-10-24   NA       NA
2 Africa Eastern and Southern    ZH   AFE 2023         2024-10-24   NA 1672.506
3  Africa Western and Central    ZI   AFW 2023         2024-10-24   NA 1584.333
4                     Albania    AL   ALB 2023         2024-10-24   NA 8367.776
5                     Algeria    DZ   DZA 2023         2024-10-24   NA 5260.206
6              American Samoa    AS   ASM 2023         2024-10-24   NA       NA
  adult_literacy life_expectancy population undernourishment
1             NA              NA   42239854               NA
2       73.27511              NA  739108306               NA
3       60.50555              NA  502789511               NA
4             NA              NA    2745972               NA
5             NA              NA   45606480               NA
6             NA              NA      43914               NA
                      region   capital longitude latitude              income
1                 South Asia     Kabul   69.1761  34.5228          Low income
2                 Aggregates                                       Aggregates
3                 Aggregates                                       Aggregates
4      Europe & Central Asia    Tirane   19.8172  41.3317 Upper middle income
5 Middle East & North Africa   Algiers   3.05097  36.7397 Lower middle income
6        East Asia & Pacific Pago Pago  -170.691 -14.2846 Upper middle income
         lending
1            IDA
2     Aggregates
3     Aggregates
4           IBRD
5           IBRD
6 Not classified