I have a dataset that is unique by household id (id99) and person id (dk10q6). There are 4,778 households, and on avg each household lists 2.7 people -- some households have only 1 person listed (1 row), and the largest household has 10 (people/rows).
I want to calculate the gini inequality in a land variable (landatdeath) across people for EACH household. Then I want to store those as a (constant-within-household) variable.
My impression is that I can do this via the following code, where sd_landatdeath is missing when there is only 1 person per household, so I'm skipping those households as they don't need a gini calculated.
However, (1) When I use ineqdeco, it does not return r(gini). I tried updating both ineqdeco and ineqdec0, as mentioned by Stephen Jenkins here. It tells me that it updated, but still no r(gini). So to be clear, when I simply run the code ineqdeco landatdeath and then type return list, I see only r(N), r(sum_w), r(sum), r(mean), r(min), r(max). Why? What do I need to update/change? I'm using Stata 17.
Also (2) Is this loop the right way to go about this? It seems to me that somebody must have written a user-written command to generate a gini coefficient (as a new var) by group. No?
Thanks!!
I want to calculate the gini inequality in a land variable (landatdeath) across people for EACH household. Then I want to store those as a (constant-within-household) variable.
My impression is that I can do this via the following code, where sd_landatdeath is missing when there is only 1 person per household, so I'm skipping those households as they don't need a gini calculated.
Code:
gen gini=. levelsof id99 if sd_landatdeath~=. , local(levels) foreach i of local levels { di `i' qui ineqdeco landatdeath if id99==`i' replace gini = r(gini) if id99==`i' }
Also (2) Is this loop the right way to go about this? It seems to me that somebody must have written a user-written command to generate a gini coefficient (as a new var) by group. No?
Thanks!!
Comment