Skip to contents

pipmd_quantile returns the quantile (i.e., monetary value) that corresponds to share of the population that lives below that threshold.

Usage

pipmd_quantile(
  welfare,
  weight = rep(1, length = length(welfare)),
  n = 10,
  popshare = seq(from = 1/n, to = 1, by = 1/n),
  format = c("dt", "list", "atomic")
)

Arguments

welfare

welfare vector

weight

population weight vector

n

numeric: number of equi-spaced quantiles

popshare

numeric atomic vector: the quantiles to return. Will only be used if n = NULL

format

character: "dt", "list", "atomic", giving the format of the output

Value

Returns a data.table and data.frame object with two variables: quantile and value. Check format argument to change the output format.

Details

This is basically the inverse of estimating the poverty rate (headcount or population share) below the poverty line. In this case, you provide the headcount and pipmd_quantile returns the "poverty line".

The quantiles are calculated as function of the mean of the distribution times an x factor. Basically, the quantile is x times the mean. By default, the mean is equal to 1, which implies that, if no mean value if provided, the return value is equal to x.

Examples

# Example 1: Calculating quintiles.
pipmd_quantile(welfare = pip_md_s$welfare,
               weight  = pip_md_s$weight,
               n       = 5,
               format  = "list")
#> $`20%`
#> [1] 1.266062
#> 
#> $`40%`
#> [1] 1.945387
#> 
#> $`60%`
#> [1] 2.986672
#> 
#> $`80%`
#> [1] 4.836562
#> 
#> $`100%`
#> [1] 18.01952
#> 

# Example 2: Calculating deciles with data.table format.
pipmd_quantile(welfare = pip_md_s$welfare,
               weight  = pip_md_s$weight,
               n       = 10,
               format  = "dt")
#>     quantile     values
#>       <char>      <num>
#>  1:    q_10%  0.8454755
#>  2:    q_20%  1.2660622
#>  3:    q_30%  1.6202722
#>  4:    q_40%  1.9453871
#>  5:    q_50%  2.3513837
#>  6:    q_60%  2.9866717
#>  7:    q_70%  3.6777302
#>  8:    q_80%  4.8365623
#>  9:    q_90%  7.3149182
#> 10:   q_100% 18.0195166

# Example 3: Calculating quantiles at specific population shares and format atomic.
specific_popshares <- seq(from = 0, to = 1, length.out = 100)
pipmd_quantile(welfare = pip_md_s$welfare,
               weight  = pip_md_s$weight,
               popshare = specific_popshares,
               format  = "atomic")
#>        10%        20%        30%        40%        50%        60%        70% 
#>  0.8454755  1.2660622  1.6202722  1.9453871  2.3513837  2.9866717  3.6777302 
#>        80%        90%       100% 
#>  4.8365623  7.3149182 18.0195166