Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Calculating Gini

From   "Stephen Jenkins" <>
To   <>
Subject   st: RE: Calculating Gini
Date   Thu, 2 Sep 2004 10:22:10 +0100

On Thu, 2 Sep 2004 00:45:53 +0530 (IST), Rijo John <>
wrote : 

 I was trying to calculate the gini coefficients using the formula

ginidesc income [fw=weight], by(state)

This gives me the desired results. But if I want to estimate it
for one more subgroup within "state", say some thing like

ginidesc income [fw=weight], by(state district)

It gives me the error

invalid syntax

Cant I specify more than one subgroup variable in the by statement of
formula? Or is there any other easy way to compute only the gini
coefficients in STATA with such "by" options. I mean, without
into "within" and "between" groups, I want to estimate only the gini
the "by" option. I had seen the command "inequal" but this doesnt have a
"by" option.

The Gini coefficients in -ginidesc- are calculated using my program

You could use -ineqdeco- directly, with its by() option to get the Ginis
for each subgroup. I think 

	ineqdeco income [fw=weight], by(state district)

should work

(Yes, you do also get the within/between decomposition for other
indices, but you do get the results you want!).

Alternatively you might wish to save the estimated results for each
subgroup Gini (you don't say).

To access the saved parameters (which are saved as global macros, with
names beginning S, as described in the help file), you need to refer to
them as $S_gini and so on <== NB the "$" prefix, which is how to refer
to global macros. [-ineqdeco- and its relatives are written in version 5
of Stata. When I find some time to update it, it will use 'modern'
syntax and you'll be able to refer to r(gini) and so on. ... but it's
only cosmetic; it works fine at present ]

To get the values for each district within state (subgroup inequality
stats), you will need to run the program looping over each subgroup
(because the macros left behind are the overall aggregate stats not
subgroup ones).
In Stata 8, you could do something like the following (untested!) to get
Ginis for each state/district combination:

gen gini-s = .     
egen subgroup = group(state district)
levels subgroup, local(levels) 
foreach i of local levels { 
	ineqdeco income [fw=weight] if subgroup == `i'
      replace gini-s = $S_gini if subgroup == `i' 

The vble gini-s will contain the subgroup gini coeffs (which should
correspond with the 
log file output from 
	ineqdeco income [fw=weight], by(subgroup)

See also about the
general principles (-levels- and all that)

If you wanted to estimate Ginis allowing for zero values for income, use
-ineqdec0- instead. Similar principles apply to saving subgroup poverty
indices after -povdeco-.

Please ensure that you have the latest versions of the programs. You 
should e.g. see the following 
. which ineqdeco
*! version 1.0.1 Stephen P. Jenkins, April 1998   STB-48 sg104
*! version 1.6 April 2001 (made compatible with Stata 7)
*! Inequality indices and decomposition by population subgroups
*! Syntax: ineqdeco <var> [[w=weight] if <exp> in <range>], 
*!              [by(<groupvar>) w s]

To update, use the SSC archive. Type 
-ssc install <progname>, replace- in an up-to-date Stata.  

Professor Stephen P. Jenkins <>
Institute for Social and Economic Research
University of Essex, Colchester CO4 3SQ, U.K.
Tel: +44 1206 873374.  Fax: +44 1206 873151.   

*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index