It was indeed a happy family reunion of Gini, Lorenz and DAD. Now, uncle R is inviting them for a free lunch.
I am doing the Gini coefficient and Lorenz curve, now with IC2 package of R. I have recently installed this package which one document describes as:
Description
The package IC2 implements the computation of some indices of inequality and concentration. For each index, it provides decomposition between subgroups. Plotting of Lorenz and concentration curves are also available.
Details
Three family of inequality indices are available: extended Gini, Atkinson and Generalized Entropy. Except for GEI, two different forms of decomposition are available. Ordinary as well as generalized Lorenz curves can be drawn. Sampling weights can be used.
Compute Gini coefficient with IC2
While creating the ASCII data file for importing into DAD software I had saved it also as an R data file ineq_HHdata.RData. The following R script created the coefficients:
# retrieve data
load(file="ineq_HHdata.RData")
# compute Gini coefficient
library(IC2)
Gincome <- calcSGini(xm$income, w = xm$hhweight)
Gconsump <- calcSGini(xm$consump, w = xm$hhweight)
cbind(Income = unlist(Gincome[[1]]), Consumption = unlist(Gconsump[[1]]))
## Income Consumption
## index.SGini 0.3192903 0.3066726
## parameter.param 2.0000000 2.0000000
Draw Lorenz curve with IC2
# draw Lorenz curves
curveLorenz(xm$income, w = xm$hhweight, xlab = "Percentiles (p)", ylab = "L(p)", col = "blue", lwd = 2)
curveLorenz(xm$consump, w = xm$hhweight, xlab = NA, ylab = NA, col = "red", lwd = 2, add = TRUE)
title(main = "Lorenz curve(s) by IC2")
legend("top",legend = c("Income", "Consumption"), cex = .8, lty = c(1,1), col = c("blue","red"), lwd = 2)
No comments:
Post a Comment