library(povcalnetR)

The povcalnetR package allows to easily query the PovcalNet API from R.

Here are a few examples to get you started:

Basic options

Filter by country

# Specify ONE country
povcalnet(country = "ALB")
#> # A tibble: 5 x 31
#>   countrycode countryname regioncode coveragetype  year datayear datatype
#>   <chr>       <chr>       <chr>      <chr>        <dbl>    <dbl> <chr>   
#> 1 ALB         Albania     ECA        N             1996     1996 consump~
#> 2 ALB         Albania     ECA        N             2002     2002 consump~
#> 3 ALB         Albania     ECA        N             2005     2005 consump~
#> 4 ALB         Albania     ECA        N             2008     2008 consump~
#> 5 ALB         Albania     ECA        N             2012     2012 consump~
#> # ... with 24 more variables: isinterpolated <dbl>, usemicrodata <dbl>,
#> #   ppp <dbl>, povertyline <dbl>, mean <dbl>, headcount <dbl>,
#> #   povertygap <dbl>, povertygapsq <dbl>, watts <dbl>, gini <dbl>,
#> #   median <dbl>, mld <dbl>, polarization <dbl>, population <dbl>,
#> #   decile1 <dbl>, decile2 <dbl>, decile3 <dbl>, decile4 <dbl>,
#> #   decile5 <dbl>, decile6 <dbl>, decile7 <dbl>, decile8 <dbl>,
#> #   decile9 <dbl>, decile10 <dbl>

# Specify MULTIPLE countries
povcalnet(country = c("ALB", "CHN"))
#> # A tibble: 53 x 31
#>    countrycode countryname regioncode coveragetype  year datayear datatype
#>    <chr>       <chr>       <chr>      <chr>        <dbl>    <dbl> <chr>   
#>  1 ALB         Albania     ECA        N             1996     1996 consump~
#>  2 ALB         Albania     ECA        N             2002     2002 consump~
#>  3 ALB         Albania     ECA        N             2005     2005 consump~
#>  4 ALB         Albania     ECA        N             2008     2008 consump~
#>  5 ALB         Albania     ECA        N             2012     2012 consump~
#>  6 CHN         China       EAP        A             1981     1981 income  
#>  7 CHN         China       EAP        A             1984     1984 income  
#>  8 CHN         China       EAP        A             1987     1987 income  
#>  9 CHN         China       EAP        A             1990     1990 consump~
#> 10 CHN         China       EAP        A             1993     1993 consump~
#> # ... with 43 more rows, and 24 more variables: isinterpolated <dbl>,
#> #   usemicrodata <dbl>, ppp <dbl>, povertyline <dbl>, mean <dbl>,
#> #   headcount <dbl>, povertygap <dbl>, povertygapsq <dbl>, watts <dbl>,
#> #   gini <dbl>, median <dbl>, mld <dbl>, polarization <dbl>,
#> #   population <dbl>, decile1 <dbl>, decile2 <dbl>, decile3 <dbl>,
#> #   decile4 <dbl>, decile5 <dbl>, decile6 <dbl>, decile7 <dbl>,
#> #   decile8 <dbl>, decile9 <dbl>, decile10 <dbl>

Other features

Get estimates when survey year is not available

The fill_gaps argument will trigger the interpolation / extrapolation of poverty estimates when survey year is not available

# fill_gaps = FALSE (default)
povcalnet(country = "HTI")
#> # A tibble: 3 x 31
#>   countrycode countryname regioncode coveragetype  year datayear datatype
#>   <chr>       <chr>       <chr>      <chr>        <dbl>    <dbl> <chr>   
#> 1 HTI         Haiti       LAC        N             2001     2001 income  
#> 2 HTI         Haiti       LAC        N             2012     2012 consump~
#> 3 HTI         Haiti       LAC        N             2012     2012 income  
#> # ... with 24 more variables: isinterpolated <dbl>, usemicrodata <dbl>,
#> #   ppp <dbl>, povertyline <dbl>, mean <dbl>, headcount <dbl>,
#> #   povertygap <dbl>, povertygapsq <dbl>, watts <dbl>, gini <dbl>,
#> #   median <dbl>, mld <dbl>, polarization <dbl>, population <dbl>,
#> #   decile1 <dbl>, decile2 <dbl>, decile3 <dbl>, decile4 <dbl>,
#> #   decile5 <dbl>, decile6 <dbl>, decile7 <dbl>, decile8 <dbl>,
#> #   decile9 <dbl>, decile10 <dbl>

# fill_gaps = TRUE
povcalnet(country = "HTI", fill_gaps = TRUE)
#> # A tibble: 15 x 31
#>    countrycode countryname regioncode coveragetype  year datayear datatype
#>    <chr>       <chr>       <chr>      <chr>        <dbl>    <dbl> <chr>   
#>  1 HTI         Haiti       XX         N             1981     2001 income  
#>  2 HTI         Haiti       XX         N             1984     2001 income  
#>  3 HTI         Haiti       XX         N             1987     2001 income  
#>  4 HTI         Haiti       XX         N             1990     2001 income  
#>  5 HTI         Haiti       XX         N             1993     2001 income  
#>  6 HTI         Haiti       XX         N             1996     2001 income  
#>  7 HTI         Haiti       XX         N             1999     2001 income  
#>  8 HTI         Haiti       XX         N             2002       NA income  
#>  9 HTI         Haiti       XX         N             2005       NA income  
#> 10 HTI         Haiti       XX         N             2008       NA income  
#> 11 HTI         Haiti       XX         N             2010       NA income  
#> 12 HTI         Haiti       XX         N             2011       NA income  
#> 13 HTI         Haiti       XX         N             2012     2012 consump~
#> 14 HTI         Haiti       XX         N             2013     2012 consump~
#> 15 HTI         Haiti       XX         N             2015     2012 consump~
#> # ... with 24 more variables: isinterpolated <dbl>, usemicrodata <dbl>,
#> #   ppp <dbl>, povertyline <dbl>, mean <dbl>, headcount <dbl>,
#> #   povertygap <dbl>, povertygapsq <dbl>, watts <dbl>, gini <dbl>,
#> #   median <dbl>, mld <dbl>, polarization <dbl>, population <dbl>,
#> #   decile1 <dbl>, decile2 <dbl>, decile3 <dbl>, decile4 <dbl>,
#> #   decile5 <dbl>, decile6 <dbl>, decile7 <dbl>, decile8 <dbl>,
#> #   decile9 <dbl>, decile10 <dbl>

Compute custom aggregates

The povcalnet function can also be used to compute aggregate welfare statistics of custom group of countries

# World aggregate
povcalnet(country = "all", aggregate = TRUE)
#> # A tibble: 15 x 9
#>    regiontitle regioncode  year povertyline  mean headcount povertygap
#>    <chr>       <chr>      <dbl>       <dbl> <dbl>     <dbl>      <dbl>
#>  1 World Total WLD         2015         1.9  459.    0.0998     0.0306
#>  2 World Total WLD         2013         1.9  442.    0.112      0.0336
#>  3 World Total WLD         2012         1.9  432.    0.128      0.0377
#>  4 World Total WLD         2011         1.9  425.    0.137      0.0407
#>  5 World Total WLD         2010         1.9  418.    0.157      0.0466
#>  6 World Total WLD         2008         1.9  409.    0.182      0.0541
#>  7 World Total WLD         2005         1.9  381.    0.207      0.0631
#>  8 World Total WLD         2002         1.9  348.    0.255      0.0823
#>  9 World Total WLD         1999         1.9  339.    0.286      0.0953
#> 10 World Total WLD         1996         1.9  329.    0.294      0.0979
#> 11 World Total WLD         1993         1.9  315.    0.340      0.120 
#> 12 World Total WLD         1990         1.9  321.    0.359      0.127 
#> 13 World Total WLD         1987         1.9  318.    0.353      0.125 
#> 14 World Total WLD         1984         1.9  304.    0.392      0.146 
#> 15 World Total WLD         1981         1.9  297.    0.421      0.179 
#> # ... with 2 more variables: povertygapsq <dbl>, population <dbl>

# Custom aggregate
povcalnet(country = c("CHL", "ARG", "BOL"), aggregate = TRUE)
#> # A tibble: 15 x 9
#>    regiontitle regioncode  year povertyline  mean headcount povertygap
#>    <chr>       <chr>      <dbl>       <dbl> <dbl>     <dbl>      <dbl>
#>  1 XX          XX          2015         1.9  645.    0.0172    0.00811
#>  2 XX          XX          2013         1.9  644.    0.0174    0.00794
#>  3 XX          XX          2012         1.9  625.    0.0205    0.00956
#>  4 XX          XX          2011         1.9  612.    0.0206    0.00851
#>  5 XX          XX          2010         1.9  575.    0.0322    0.0140 
#>  6 XX          XX          2008         1.9  544.    0.0382    0.0169 
#>  7 XX          XX          2005         1.9  473.    0.0582    0.0260 
#>  8 XX          XX          2002         1.9  334.    0.130     0.0574 
#>  9 XX          XX          1999         1.9  452.    0.0762    0.0418 
#> 10 XX          XX          1996         1.9  468.    0.0622    0.0334 
#> 11 XX          XX          1993         1.9  477.    0.0443    0.0188 
#> 12 XX          XX          1990         1.9  458.    0.0377    0.0123 
#> 13 XX          XX          1987         1.9  576.    0.0423    0.0127 
#> 14 XX          XX          1984         1.9  598.    0.0496    0.0151 
#> 15 XX          XX          1981         1.9  583.    0.0308    0.00983
#> # ... with 2 more variables: povertygapsq <dbl>, population <dbl>