Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating Gini Coefficient (Using ineqdeco Command) as a Variable by Group

    Dear Statalist,

    I recently learned that one of the ways to generate Gini Coefficient is to use ineqdeco command.
    I wanted to directly include the derived Gini coefficient value as a variable such as below.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(group id income)
    1 1      0
    1 2   5000
    1 3  12000
    1 4  18000
    2 5  30000
    2 6  40000
    2 7  60000
    3 8 100000
    3 9 150000
    end
    Using the above example data set, if I run the below code, I create a variable "gini_for_all" which includes the derived Gini coefficient from all the id(s) based on their income values.
    Code:
    ineqdeco income
    gen gini_for_all=r(gini)
    But I am trying to take one step further; what I want to do is I want to generate Gini coefficient that is calculated for each group and include each within "gini_for_group" variable.
    I thought "by group" or "bysort group" were going to work but the error message returned me "ineqdeco may not be combined with by".
    Is there a clever way to address this?
    Thank you.

  • #2
    Code:
    ineqdeco income, by(group)

    Comment


    • #3
      Thank you for the prompt reply!
      I should have carefully looked at the manual.

      May I also ask how I can assign the three different Gini coefficient values for each sub-group in a newly created variable?
      I found that
      Code:
      r(gini_k)
      returns the Gini value for each subgroup k but
      Code:
      display r(gini_k)
      actually returns nothing.

      ->updated question:
      I knew that I should type in these separately.
      Code:
      display r(gini_1)
      display r(gini_2)
      display r(gini_3)
      Is there a way to return these at once in the command?
      Last edited by Ryan Kim; 08 Jan 2022, 06:19. Reason: Question Updated

      Comment


      • #4
        perhaps,
        Code:
        display r(gini_1) _skip(5) r(gini_2) _skip(5) r(gini_3)
        or,
        Code:
        mat m = r(gini_1) \ r(gini_2) \ r(gini_3)
        mat list m

        Comment

        Working...
        X