Skip to contents

Load and prep data

data("md_ABC_2000_income")

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

Compute PIP poverty stats

# Poverty line needs to be expressed in monthly international dollar values
# The conversion from daily to monthly values needs to happen at a higher level
# in the functions call stack for efficiency purposes
poverty_line <- 1.9 * 365 / 12

# default_ppp
# This will need to be provided directly by a potential end-users
# For production use: This value will be fed directly to the function depending 
# on the requested country / year.
ppp_value <- 58.16

# requested mean
# This is the survey mean in internationl dollars
# The conversion from LCU to international dollars needs to happen at a higher 
# level in the fucntion call stack for efficiency purposes.
# This parameter is also used for interpolation computation to query the welfare
# distribution using a different mean.
welfare_mean <- 225

out <- wbpip:::md_compute_pip_stats(welfare        = df$welfare,
                                    population     = df$weight,
                                    povline        = poverty_line,
                                    default_ppp    = ppp_value,
                                    requested_mean = welfare_mean)
out
#> $poverty_line
#> [1] 57.79167
#> 
#> $mean
#> [1] 225
#> 
#> $median
#> [1] 132.9027
#> 
#> $headcount
#> [1] 0.1418472
#> 
#> $poverty_gap
#> [1] 0.051882
#> 
#> $poverty_severity
#> [1] 0.02683585
#> 
#> $watts
#> [1] 0.07785021
#> 
#> $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