Skip to contents

Compute the Gini coefficient for microdata.

Usage

pipmd_gini(
  welfare,
  weight = rep(1, length = length(welfare)),
  format = c("dt", "list", "atomic")
)

Arguments

welfare

welfare vector

weight

population weight vector

format

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

Value

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

Details

Given a vector of income or consumption values and their respective weights pipmd_gini() computes the Gini coefficient for the distribution.

Examples

# Example 1: Basic Gini coefficient calculation with default settings
pipmd_gini(welfare = pip_md_s$welfare,
           weight = pip_md_s$weight)
#>    indicator     value
#>       <char>     <num>
#> 1:      gini 0.4190533

# Example 2: Returning Gini coefficient in data.table format
pipmd_gini(welfare = pip_md_s$welfare,
           weight = pip_md_s$weight,
           format = "dt")
#>    indicator     value
#>       <char>     <num>
#> 1:      gini 0.4190533

# Example 3: Returning Gini coefficient as an atomic value
pipmd_gini(welfare = pip_md_s$welfare,
           weight = pip_md_s$weight,
           format = "atomic")
#>      gini 
#> 0.4190533 
#> attr(,"label")
#> [1] "welfare(income of consumption)"

# Example 4: Using equal weights (weight vector is NULL)
pipmd_gini(welfare = pip_md_s$welfare,
           format = "list")
#> $gini
#> [1] 0.4080793
#>