Giter Club home page Giter Club logo

povcalnetr's Introduction

!! ARCHIVED PACKAGE !! Please read below

The PovcalNet website and API have now been retired, and replaced by the Poverty and Inequality Platform (PIP). As a result, the PovcanetR API client is now longer relevant. Please use the pipR package instead to interact with the PIP API. Thanks!

povcalnetR

Travis build status AppVeyor build status Coverage status Lifecycle: maturing CRAN status CRAN

The povcalnetR package allows R users to compute poverty and inequality indicators for more than 160 countries and regions from the World Bank’s database of household surveys. It has the same functionality as the PovcalNet website. PovcalNet is a computational tool that allows users to estimate poverty rates for regions, sets of countries or individual countries, over time and at any poverty line.

PovcalNet is managed jointly by the Data and Research Group in the World Bank’s Development Economics Division. It draws heavily upon a strong collaboration with the Poverty and Equity Global Practice, which is responsible for the gathering and harmonization of the underlying survey data.

PovcalNet reports the following measures at the chosen poverty line:
- Headcount ratio
- Poverty Gap
- Squared Poverty Gap
- Watts index

It also reports these inequality measures:
- Gini index
- mean log deviation
- decile shares

The underlying welfare aggregate is per capita household income or consumption expressed in 2011 PPP-adjusted USD. Poverty lines are expressed in daily amounts, while means and medians are monthly.

For more information on the definition of the indicators, click here
For more information on the methodology, click here

Installation

You can install the released version of povcalnetR from CRAN with:

install.packages("povcalnetR")

The development version can be installed from GitHub with:

install.packages(c("devtools", "httr"))
devtools::install_github("worldbank/povcalnetR")

Example

This is a basic example that shows how to retrieve some key poverty statistics from PovcalNet using this package

library(povcalnetR)
library(dplyr)

df <- povcalnet(country = "ALB")
glimpse(df)
#> Observations: 5
#> Variables: 31
#> $ countrycode    <chr> "ALB", "ALB", "ALB", "ALB", "ALB"
#> $ countryname    <chr> "Albania", "Albania", "Albania", "Albania", "Al...
#> $ regioncode     <chr> "ECA", "ECA", "ECA", "ECA", "ECA"
#> $ coveragetype   <chr> "N", "N", "N", "N", "N"
#> $ year           <dbl> 1996, 2002, 2005, 2008, 2012
#> $ datayear       <dbl> 1996, 2002, 2005, 2008, 2012
#> $ datatype       <chr> "consumption", "consumption", "consumption", "c...
#> $ isinterpolated <dbl> 0, 0, 0, 0, 0
#> $ usemicrodata   <dbl> 1, 1, 1, 1, 1
#> $ ppp            <dbl> 58.16801, 58.16801, 58.16801, 58.16801, 58.16801
#> $ povertyline    <dbl> 1.9, 1.9, 1.9, 1.9, 1.9
#> $ mean           <dbl> 187.8427, 191.9880, 217.0335, 237.5353, 225.2692
#> $ headcount      <dbl> 0.011291240, 0.020473200, 0.011237280, 0.003705...
#> $ povertygap     <dbl> 0.0019115400, 0.0035450460, 0.0018274740, 0.000...
#> $ povertygapsq   <dbl> 0.0005560317, 0.0010593800, 0.0004780857, 0.000...
#> $ watts          <dbl> 0.0023108880, 0.0043677770, 0.0021404260, 0.000...
#> $ gini           <dbl> 0.2701034, 0.3173898, 0.3059566, 0.2998467, 0.2...
#> $ median         <dbl> 165.0867, 158.3630, 184.6848, 198.7757, 195.0467
#> $ mld            <dbl> 0.1191043, 0.1648116, 0.1544128, 0.1488934, 0.1...
#> $ polarization   <dbl> NA, NA, NA, NA, NA
#> $ population     <dbl> 3.168033, 3.051010, 3.011487, 2.947314, 2.900401
#> $ decile1        <dbl> 0.03863, 0.03494, 0.03483, 0.03734, 0.03660
#> $ decile2        <dbl> 0.05289, 0.04859, 0.04920, 0.05137, 0.05193
#> $ decile3        <dbl> 0.06379, 0.05842, 0.05977, 0.06088, 0.06144
#> $ decile4        <dbl> 0.07322, 0.06738, 0.06921, 0.06984, 0.07031
#> $ decile5        <dbl> 0.08380, 0.07653, 0.07988, 0.07912, 0.08084
#> $ decile6        <dbl> 0.09355, 0.08839, 0.09037, 0.08924, 0.09257
#> $ decile7        <dbl> 0.1082, 0.1023, 0.1037, 0.1030, 0.1052
#> $ decile8        <dbl> 0.1247, 0.1198, 0.1213, 0.1193, 0.1229
#> $ decile9        <dbl> 0.1490, 0.1493, 0.1483, 0.1454, 0.1489
#> $ decile10       <dbl> 0.2122, 0.2544, 0.2434, 0.2446, 0.2293

povcalnetr's People

Contributors

randrescastaneda avatar rmitra90 avatar tonyfujs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

povcalnetr's Issues

Region code not correctly returned

When using the option fill_gaps=True, the regions are all returned as "XX."

poverty <- povcalnet(year = 2015, fill_gaps = TRUE)
poverty <- povcalnet(year = 2015)

Options to suppress the messages produced by read_csv

The povcalnet function uses readr::read_csv to format the data. By the default configuration for readr (version > 2.0), messages about the dataframe column types will pop up once the data is read. readr::read_csv offers an argument show_col_types to switch off the sometimes annoying messages. However, such an argument is not available when using povcalnet.

Fix package data to avoid out of sync situation

Currently, package internal variable are being defined at build time in add_internal_data.R
This is an issue for variables that are pulled from the API using povcalnet_info(). This approach breaks in the following cases:

  • Information is updated on povcalnet PROD but the package is not being updated
  • package is used on testing servers, but information is pulled from PROD

No interpolated results returned with the argument "fill_gaps==TRUE"

Hi,
The argument fill_gaps of povcalnet() is described as "logical: 'TRUE' will interpolate / extrapolate values when surveys are not available for a specific year." However, no interpolated result (poverty headcount/gini etc) is returned when this argument is TRUE. I requested data for all countries with fill_gaps==TRUE and got a returned dataframe with a variable isinterpolated. It turns out that isinterpolated is always 0 (indicates no interpolation), and the total amount of data is equal to that with fill_gaps==FALSE.

Is there a mistake in this function or something I have misunderstood?
Really need the interpolated data (or methodology). Thanks in advance.

Limit of 76 poverty lines per povcalnet_cl request in R?

For example this works:
povcalnet_cl(rep("CHN",76),seq(0.01,0.76,0.01),rep(2010,76))
while this:
povcalnet_cl(rep("CHN",77),seq(0.01,0.77,0.01),rep(2010,77))
produces an error:
"Error: assert_that: assertion must return a logical value"
[using a fully updated R version 3.6.1 (2019-07-05) on Ubuntu 18.04.3 LTS]

R session stucked when retrieving data for certain countries

I am using povcalnetR to get the poverty headcounts for each country in a loop. However, the loop always gets stuck at some point such that I have to force shut down my R software. After checking the code, I found that certain countries caused the problem, e.g.:

library(povcalnetR)
povcalnet(
    country = "SUR", povline = 1.9, year = 2010:2021
  )

If country="all", the code works fine, and the retrieved data will not contain information for the problematic country "SUR". It seems that if a country is not in the database, the data retrieval for that individual country will raise a bug.

Other information:

  • System: Windows 10
  • R version: 4.1.1
  • povcalnetR_0.1.1

Sometimes headcount is -1

try:
povcalnet("GNB",10,1991)
gives: -1 to headcount povertygap povertygapsq watts
it should give 1 to headcount at least

default of argument coverage() should be "all"

Hi Tony,

By default, the Stata package loads coverages levels when option coverage is left empty povcalnet, country("all"). However, the R package filters everything that is not national by default. In this case, countries like Argentina, which does not have national coverage, are excluded from the output when povcalnet(country = "all") is executed.

I could update that if you want, but I thought it would be better if you do it.

Thanks.
Best,
Andres

povcalnet_wb() reports data apparently unavailable in web interface.

The following lines of code will report a row with data for region SAS in 2015 but NAs for 2018.

library(povcalnetR)
regions <- povcalnet_wb()
regions <- regions[regions$regioncode == "SAS",]
regions[regions$year == 2015,]
regions[regions$year == 2018,]

The PovcalNet web interface, however, suppresses the results for both years as coverage in 2015 and 2018 in SAS is too low.

This inconsistency seems weird.

Ryan

povcalnet_cl does not return full results when using different poverty lines

In more detail the results are as follows (the rest of countries seem to return poverty rates for all survey years when poverty lines other than 1.9 $ are requested--not necessarily the same for each year):
[1] "PCN request for ARG returns an empty tibble (own PLs)."
[1] "PCN request for BOL returns a tibble with less years (own PLs). Missing: 1992"
[1] "PCN request for COL returns a tibble with less years (own PLs). Missing: 1980;1988;1989;1991"
[1] "PCN request for ECU returns a tibble with less years (own PLs). Missing: 1995"
[1] "PCN request for ETH returns a tibble with less years (own PLs). Missing: 1981"
[1] "PCN request for HND returns a tibble with less years (own PLs). Missing: 1986"
[1] "PCN request for URY returns a tibble with less years (own PLs). Missing: 1992;1995;1996;1997;1998;2000;2001;2002;2003;2004;2005"

povcalnet() doesn't pull ARE

It would appear that the povcalnet() function doesn't pull data for ARE. Even if I try using povcalnet(country = "ARE") it just returns an empty dataframe. Data exists on the povcal website so I'm not sure why the package ignores it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.