Announcement

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

  • ineqdeco: why don't I get r(gini), am I doing this loop right?

    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.

    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'
    }
    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!!
    Last edited by Leah Bevis; 09 Sep 2023, 12:03.

  • #2
    doesn't look like ineqdeco stores anything interesting in the return list

    Comment


    • #3
      looks like the gini is stored in a global.

      try this:

      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 = $S_gini if id99==`i' }

      Comment


      • #4
        Users of -ineqdeco- and -ineqdec0- should ensure that they have the latest versions (on SSC). Results were returned in global macros in early versions; they have also been returned in r() for around a decade, I recall. Proof of concept below

        Code:
        . which ineqdeco
        d:\home\stephenj\ado\stbplus\i\ineqdeco.ado
        *! 2.1.0 SPJ Feb 2021 Add pweight so that use PVK's -rhsbsample- & svy bootstrap
        *! 2.0.2 SPJ May 2008 (fix bug arising if bygroup() and `touse' lead to no obs in a group)
        *!   bug fix method provided by Austin Nichols (many thanks!)
        *! 2.0.1 SPJ August 2006 (new vbles created as doubles)
        *! 2.0.0 SPJ August 2006 (port to Stata 8.2; additional saved results),
        *!   with initial code rewriting contribution from Nick Cox (many thanks!)
        *! version 1.6 April 2001 (made compatible with Stata 7; SSC)
        *! version 1.0.1 Stephen P. Jenkins, April 1998   STB-48 sg104
        *! Inequality indices, with optional decomposition by population subgroups
        
        . sysuse auto
        (1978 automobile data)
        
        . ineqdeco weight
         
        Percentile ratios
        
        ----------------------------------------------------------
          All obs |    p90/p10     p90/p50     p10/p50     p75/p25
        ----------+-----------------------------------------------
                  |      2.010       1.273       0.633       1.607
        ----------------------------------------------------------
          
        Generalized Entropy indices GE(a), where a = income difference
         sensitivity parameter, and Gini coefficient
        
        ----------------------------------------------------------------------
          All obs |     GE(-1)       GE(0)       GE(1)       GE(2)        Gini
        ----------+-----------------------------------------------------------
                  |    0.03602     0.03408     0.03300     0.03268     0.14605
        ----------------------------------------------------------------------
          
        Atkinson indices, A(e), where e > 0 is the inequality aversion parameter
        
        ----------------------------------------------
          All obs |     A(0.5)        A(1)        A(2)
        ----------+-----------------------------------
                  |    0.01665     0.03351     0.06719
        ----------------------------------------------
        
        . return list
        
        scalars:
                         r(a2) =  .0671913422176406
                         r(a1) =  .0335077498211571
                      r(ahalf) =  .0166505324127778
                        r(ge2) =  .0326784262520654
                        r(ge1) =  .0329985720447048
                        r(ge0) =  .0340819988047589
                       r(gem1) =  .0360156081620104
                       r(gini) =  .1460468255581035
                     r(p75p50) =  1.128526645768025
                     r(p25p50) =  .7021943573667712
                     r(p10p50) =  .6332288401253918
                     r(p90p50) =  1.272727272727273
                     r(p75p25) =  1.607142857142857
                     r(p90p10) =  2.00990099009901
                        r(p95) =  4290
                        r(p90) =  4060
                        r(p75) =  3600
                        r(p50) =  3190
                        r(p25) =  2240
                        r(p10) =  2020
                         r(p5) =  1830
                        r(max) =  4840
                        r(min) =  1760
                          r(N) =  74
                       r(sumw) =  74
                         r(sd) =  777.1935671373662
                        r(Var) =  604029.8407997037
                       r(mean) =  3019.45945945946

        Comment


        • #5
          Hi Stephen -- I had tried to replace both relevant ado files (using the replace commands you gave to somebody else, linked above) but when I use this "which ineqdeco" inquiry (very helpful! didn't know this was a thing!) I find that I'm stilling using your 1.0.1 version. No idea why the replace isn't working, trying to figure that out now.
          Last edited by Leah Bevis; 11 Sep 2023, 04:18.

          Comment


          • #6
            Originally posted by Leah Bevis View Post
            No idea why the replace isn't working, trying to figure that out now.
            Type

            Code:
            ado
            and locate the package (all of its variants). Then if it is package #29, for example, type

            Code:
            ado uninstall [29]
            Once you have removed all older packages, install from SSC.

            Code:
            ssc install ineqdeco, replace

            Comment


            • #7
              Good advice from Andrew (as ever). -which ineqdeco- should, I recall, tell you all the locations for ineqdeco.ado that Stata can "see". Leah: my conjecture is that you have versions of ineqdeco.ado in multiple locations, and Stata is using one of the old ones.

              Comment


              • #8
                Ah, thank you so much! And Stephen, interesting. It is always this sort of back-end storage structure that kills me, I just don't know enough about how Stata actually works in my laptop to handle such issues. Thank you both so much. And for any future readers, now that I've updated ineqdeco using the method described above by Andrew (i.e., deleting previously-installed ado packages by name before re-installing ineqdeco), the loop above works perfectly (thought obviously takes forever to loop through thousands of households).
                Last edited by Leah Bevis; 11 Sep 2023, 09:23.

                Comment


                • #9
                  if you're just interested in the gini, then you can look at ineqdeco and use the formula there. it is not that complicated (it's at line 110) and is based on rather simple code beforehand.

                  Comment

                  Working...
                  X