The pipr package allows to easily query the PIP API from R.

Here are a few examples to get you started:

Using default options

By default, get_stats() returns all available

  • countries
  • reporting levels (national, urban, rural)
  • for all available survey years
  • at the 2.15 USD a day poverty line (in 2017 PPP)

For the most recent data available.

Basic options

Filter by country

# Specify ONE country
get_stats(country = "ALB")

# Specify MULTIPLE countries
get_stats(country = c("ALB", "CHN"))

Filter by year

By default, get_stats will only return data if a survey is available for the requested country and the requested year.

# Survey year available
get_stats(country = "ALB", year = 2012)         # single year
get_stats(country = "ALB", year = c(1996,2012)) # multiple years

# Survey year NOT available - Empty response
get_stats(country = "ALB", year = 2000)

# Most Recent Value available
get_stats(country = "ALB", year = "MRV")

Modify the poverty line

get_stats(country = "ALB", povline = 3.2)

Other features

Get estimates when survey year is not available

The fill_gaps argument triggers the interpolation / extrapolation of poverty estimates when surveys are not available for a given year.

# fill_gaps = FALSE (default)
get_stats(country = "HTI")
# fill_gaps = TRUE
get_stats(country = "HTI", fill_gaps = TRUE)

Compute aggregates

get_stats() can also be used to compute aggregate welfare statistics for sub-regions. Only World Bank regions are currently available, but more sub-regional groupings will become available in the future.

# World Bank aggregate
get_stats(country = "all", subgroup = "wb_regions")
# List of World Bank regions
get_regions()

A note on caching

Finally, a short note on how pipr uses caching. By default, pipr caches the results of API calls in a local cache. This is to avoid unnecessary API calls and to speed up subsequent calls. The cache is stored in a temporary directory and is cleared after 2 hours. Practically, this means that if you call the same function with the same arguments within 2 hours, the result will be returned from the cache and not from the API.

Here is what the console will show when caching: Caching

And here is what it will show if it is retrieving a result from the cache: Retrieving