I have a data set that contains income data and a group identifier. Sort of
like:
DATA
Group,Income
A,2300
B,6776
A,6668
A,6768
B,9879
C,5577
A,7867
(etc),(etc)
I am trying to compute the gini coefficient for each group.
I have tried the following and none seem to do the trick:
1)
attach(DATA)
by(DATA, group, function(x) gini(income))
2)
attach(data)
tapply(income, group, function(x) gini(income))
Both of these return the same value for all groups. Like:
group: A
[1] 0.2422496
------------------------------------------------------------
group: B
[1] 0.2422496
------------------------------------------------------------
group: C
[1] 0.2422496
------------------------------------------------------------
group: D
[1] 0.2422496
Any ideas on how I can make this work? I need the fastest way since I am
gonna run a monte carlo based on this routine once I get the basics working.
Thanks,
EG
[[alternative HTML version deleted]]