Skip to contents

pipmd_quantile_welfare_share returns the share of welfare held by a particular quantile. Notice that pipmd_welfare_share_at get the share of welfare held by a particular share of the population, which is in a sense the cumulative share. Instead, pipmd_quantile_welfare_share returns the proportion of welfare that only the specified quantile holds.

Usage

pipmd_quantile_welfare_share(
  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 share_at. Check format argument to change the output format.

Examples

# Example 1: Basic usage with default quantiles (10)
pipmd_quantile_welfare_share(welfare = pip_md_s$welfare,
                             weight = pip_md_s$weight)
#>     quantile   share_at
#>       <char>      <num>
#>  1:    q_10% 0.01599470
#>  2:    q_20% 0.03758688
#>  3:    q_30% 0.04517520
#>  4:    q_40% 0.06755463
#>  5:    q_50% 0.06777595
#>  6:    q_60% 0.10813059
#>  7:    q_70% 0.08360875
#>  8:    q_80% 0.14695423
#>  9:    q_90% 0.18607431
#> 10:   q_100% 0.24114476

# Example 2: Specifying a different number of quantiles
pipmd_quantile_welfare_share(welfare = pip_md_s$welfare,
                             weight = pip_md_s$weight,
                             n = 5,  # For quintiles
                             format = "list")
#> $`20%`
#> [1] 0.05358158
#> 
#> $`40%`
#> [1] 0.1127298
#> 
#> $`60%`
#> [1] 0.1759065
#> 
#> $`80%`
#> [1] 0.230563
#> 
#> $`100%`
#> [1] 0.4272191
#> 

# Example 3: Using specific population shares
specific_popshares <- seq(from = 0.1, to = 1, by = 0.1)  # Deciles
pipmd_quantile_welfare_share(welfare = pip_md_s$welfare,
                             weight = pip_md_s$weight,
                             popshare = specific_popshares,
                             format = "dt")
#>     quantile   share_at
#>       <char>      <num>
#>  1:    q_10% 0.01599470
#>  2:    q_20% 0.03758688
#>  3:    q_30% 0.04517520
#>  4:    q_40% 0.06755463
#>  5:    q_50% 0.06777595
#>  6:    q_60% 0.10813059
#>  7:    q_70% 0.08360875
#>  8:    q_80% 0.14695423
#>  9:    q_90% 0.18607431
#> 10:   q_100% 0.24114476
rm(specific_popshares)

# Example 4: Returning atomic format
pipmd_quantile_welfare_share(welfare = pip_md_s$welfare,
                             weight = pip_md_s$weight,
                             n = 4,  # For quartiles
                             format = "atomic")
#>       25%       50%       75%      100% 
#> 0.0840979 0.1499895 0.2535388 0.5123738