Skip to contents

Load and prep data

User supplied data

welfare_mean    <- 51.56
ppp             <- 58.16
daily_povline   <- 1.9
monthly_povline <- daily_povline * 365 / 12

Microdata

data("md_ABC_2000_income")

# Basic cleaning operation (remove missings, negative values, etc.)
micro <- wbpip:::md_clean_data(md_ABC_2000_income, 
                              welfare = "welfare", 
                              weight  = "weight")
#>  Data has been sorted by variable "welfare"
micro <- micro$data
# Turn welfare vector to monthly values
# All computations assume monthly welfare values
micro$welfare <- micro$welfare / 12

Grouped data

# Create grouped data (Type 1)
# http://iresearch.worldbank.org/povcalnet/PovCalculator.aspx
population <- c(0.0005,
                0.0032,
                0.014799999999999999,
                0.0443,
                0.0991,
                0.257,
                0.4385,
                0.5938,
                0.7089,
                1)

welfare <- c(5.824760527229386e-05,
             0.000604029410841011,
             0.0037949334793616948,
             0.013988878652244477,
             0.036992164583098786,
             0.12140708906131342,
             0.24531391873082081,
             0.37446670169288321,
             0.48753116241194566,
             1)

Compute poverty stats

On microdata


out <- compute_pip_stats(welfare           = micro$welfare,
                         povline           = monthly_povline,
                         population        = micro$weight,
                         requested_mean    = welfare_mean,
                         popshare          = NULL,
                         default_ppp       = ppp,
                         ppp               = NULL,
                         distribution_type = "micro")

out
#> $poverty_line
#> [1] 57.79167
#> 
#> $mean
#> [1] 51.56
#> 
#> $median
#> [1] 30.4554
#> 
#> $headcount
#> [1] 0.7500095
#> 
#> $poverty_gap
#> [1] 0.4167835
#> 
#> $poverty_severity
#> [1] 0.2715343
#> 
#> $watts
#> [1] 0.7365017
#> 
#> $gini
#> [1] 0.5147999
#> 
#> $mld
#> [1] 0.473487
#> 
#> $polarization
#> [1] 0.469777
#> 
#> $deciles
#>  [1] 0.01348020 0.02630982 0.03516682 0.04436668 0.05461301 0.06523872
#>  [7] 0.08463966 0.10850619 0.15757546 0.41010343

On grouped data


out <- compute_pip_stats(welfare           = welfare,
                         povline           = monthly_povline,
                         population        = population,
                         requested_mean    = welfare_mean,
                         popshare          = NULL,
                         default_ppp       = ppp,
                         ppp               = NULL,
                         distribution_type = "group")

out
#> $poverty_line
#> [1] 57.79167
#> 
#> $mean
#> [1] 51.56
#> 
#> $median
#> [1] 42.58973
#> 
#> $headcount
#> [1] 0.7184622
#> 
#> $poverty_gap
#> [1] 0.2714275
#> 
#> $poverty_severity
#> [1] 0.1293701
#> 
#> $watts
#> [1] 0.3788881
#> 
#> $gini
#> [1] 0.3123674
#> 
#> $mld
#> [1] 0.1633424
#> 
#> $polarization
#> [1] 0.2556375
#> 
#> $deciles
#>  [1] 0.03750486 0.04963605 0.05871314 0.06775231 0.07741935 0.08831018
#>  [7] 0.10132911 0.11835493 0.14500187 0.25597820