define prepare ().
* select only records if dhi filled.
select if dhi ne 0 .
select if not missing(dhi) .
* create person weight as hwgt times number of household members.
compute wt = hwgt*nhhmem .
weight by wt.
!enddefine .
define ginicalc ().
* set equivalence scale as square root of number of household members.
compute ey = dhi/(nhhmem**0.5).
aggregate outfile = *
mode = addvariables
/ break = did
/ ey_median = median(ey)
/ ey_mean = mean(ey)
/ inc_median = median(dhi)
/ inc_mean = mean(dhi)
/ n = n .
*** LIS top and bottomcoding.
if dhi gt (10*inc_median) ey = (10*inc_median)/nhhmem**0.5 .
if ey lt (0.01*ey_mean) ey = 0.01*ey_mean .
*** gini procedure.
sort cases by ey (a).
compute cumwgt = cumwgt + wt.
leave cumwgt.
compute devey = ey - ey_mean.
compute rank = cumwgt/n.
compute devr = (rank - 0.5).
compute prod = devey*devr.
aggregate outfile= *
/ break = did
/ sumprod = sum(prod)
/ meaney = mean(ey)
/ n = n .
compute cov = sumprod/(n-1).
compute gini = cov*2/meaney.
formats gini (f10.4).
descriptives variables = gini.
!enddefine .
get file = ccyyh /keep = did hwgt nhhmem dhi.
prepare .
ginicalc.