Welfare share by quantile in micro data
pipmd_welfare_share_at.Rdpipmd_welfare_share_at returns the share of welfare held by the specified
share of the population in the parameter popshare. Alternatively, you can
select the number of quantiles (10 be default), to estimate the corresponding
share of welfare in each.
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_welfare_share_at(welfare = pip_md_s$welfare,
weight = pip_md_s$weight)
#> quantile share_at
#> <char> <num>
#> 1: q_10% 0.1088235
#> 2: q_20% 0.2070236
#> 3: q_30% 0.2993178
#> 4: q_40% 0.4131093
#> 5: q_50% 0.4988916
#> 6: q_60% 0.6124656
#> 7: q_70% 0.7001452
#> 8: q_80% 0.8032207
#> 9: q_90% 0.9117696
#> 10: q_100% 1.0000000
# Example 2: Specifying a different number of quantiles
pipmd_welfare_share_at(welfare = pip_md_s$welfare,
weight = pip_md_s$weight,
n = 5, # For quintiles
format = "list")
#> $`20%`
#> [1] 0.2070236
#>
#> $`40%`
#> [1] 0.4131093
#>
#> $`60%`
#> [1] 0.6124656
#>
#> $`80%`
#> [1] 0.8032207
#>
#> $`100%`
#> [1] 1
#>
# Example 3: Using specific population shares
specific_popshares <- seq(from = 0.1, to = 1, by = 0.1) # Deciles
pipmd_welfare_share_at(welfare = pip_md_s$welfare,
weight = pip_md_s$weight,
popshare = specific_popshares,
format = "dt")
#> quantile share_at
#> <char> <num>
#> 1: q_10% 0.1088235
#> 2: q_20% 0.2070236
#> 3: q_30% 0.2993178
#> 4: q_40% 0.4131093
#> 5: q_50% 0.4988916
#> 6: q_60% 0.6124656
#> 7: q_70% 0.7001452
#> 8: q_80% 0.8032207
#> 9: q_90% 0.9117696
#> 10: q_100% 1.0000000
# Example 4: Returning atomic format
pipmd_welfare_share_at(welfare = pip_md_s$welfare,
weight = pip_md_s$weight,
n = 4, # For quartiles
format = "atomic")
#> 25% 50% 75% 100%
#> 0.2641149 0.4988916 0.7536647 1.0000000