Announcement

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

  • Calculating GINI coefficients

    Hi everbody,

    I am new here. If you need something more like data or something else, tell me please. But for answering this question, I think you wont need the Data.

    I have the wages of basketball players for each team in the NBA in the period of 2001 till 2014. My question is, how I can calculate GINI coefficient in Stata for every team in year x. I am writing because calculating it in Excel takes to much time, especially when i want to modify the wages later.

    So for example, I need all the Gini coefficients for Team Cleveland in the year 2001, 2002, 2003, ..., 2014. And so for the next team.

    I also installed the DASP. If anybody has suggestions how to calculate the GINI coefficients with this extra program for STATA or any suggestions how to calculate the GINI in Excel efficiently, or suggestions for another way, I would be very happy.

    Thank you very much for a fast answer.

    With kind regards,

    Stan
    Last edited by Stan Breetman; 30 Jun 2017, 07:53.

  • #2
    Code:
    findit gini
    finds several options for calculating the Gini coefficient in Stata.

    Comment


    • #3
      Thank you. But since I am a beginner in Stata, how can I use a command and tell Stata to calculate just for the same team name and the same year?

      And when I type findit gini, what are these, some programms to download?

      Maybe anybody knows the command for my problem?
      Last edited by Stan Breetman; 01 Jul 2017, 05:08.

      Comment


      • #4
        For a beginner a good way to start would be the "Getting started with Stata" guide that is part of the PDF documentation that comes with Stata
        Code:
        help gs
        .

        Comment


        • #5
          Sorry Mr. Huebler, but thats no concrete help for my question.

          Comment


          • #6
            Stan:
            you may want to consider the user-written programmes -descogini- or -ineqdeco-, that you can install by typing -search descogini- or -search ineqdeco- from within Stata.
            A toy-example possibly related to your query:
            Code:
            . sysuse auto.dta
            (1978 Automobile Data)
            
            . descogini price foreign if rep78==3 & gear_ratio<=4
            
            Gini Decomposition by Income Source
            
            Total Income Variable: price
            ----------------------------------------------------------------------
            Source           Sk           Gk          Rk        Share     % Change
            ----------------------------------------------------------------------
            foreign        0.0000       0.9000     -0.2840     -0.0000    -0.0000
            Total income                0.2625
            ----------------------------------------------------------------------
            Please do not underestimate Friedrich's wise advice about getting yourself familiar with Stata bread and butter.
            As per FAQ, posters are expected to search a solution for their own problem on Statalist, web or other sources.
            Had you googled with the string -calculating gini index with Stata- you would have found out some promising entries yourself.
            Besides (as per FAQ again), the best way to increase your chances of getting helpful replies is to post what you typed and what Stata gave you back and/or posting an example/excerpt of your dataset via -dataex- (type -search dataex- from within Stata to install it).
            Put differently, as the whole forum works on goodwill, please help interested listers help yourself out by fulfilling the basic requirements of posting and Stata knowledge. Thanks.
            We all passed through this seemingly unpleasant stage of devoting time to learn Stata language backbone (and I'm still learning it with interest after arbout 10 years), but, unfortunately, there's no faster approach.
            I do hope that you enjoy staying with us despite some initial drawbacks.
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              Hi Carlo,

              thank you very much. I appreciate your and Mr. Hueblers help really. I will try to do so as you have said.
              Your code is interesting and I have already read in google and forums about these comands.
              The thing is, I couldnt find any solution for calculating Gini Coefficient with the goal to have finaly the following output for example:
              (I am using Stata 13) Something like: Stata should use the wages of the same team in the same year and so on..

              Year Team GiniCoefficient (I am using numbers for teams, instead of team names )
              ---------------------------------------------------
              2001 Cleveland 0.45
              2002 Cleveland 0.35
              ...
              2014 Cleveland 0.51
              ----------------------------------------------------
              2001 San Antonio Spyrs 0.38
              2002 San Antonio Spyrs 0.48
              ...
              2013 San Antonio Spyrs 0.47
              ----------------------------------------------------
              ... and so on for every team


              With the goal finally, not to giving around 420 comands (for every Team in the specific year to calculate), but rather to calculate the GINIs for all Teams in every year from 2001 to 2014 with one comand.

              So my question is, if there is such a comand which one it is. If it would be the code suggested by Carlo, then my question would be, how can i define the code, so excel works with the mentioned criteria.

              I hope somebody can help me soon. I will try to find out more .

              Kind regards
              Ivan
              Last edited by Stan Breetman; 01 Jul 2017, 13:43.

              Comment


              • #8
                In the made-up example below inspired by Carlo's post I use the user-written ineqdeco command to calculate "gini coefficients" for price in the auto dataset, separate for each combination of foreign/domestic and reputation(1 to 5). This is similar to calculating the gini coefficient for wage separately for each combination of team and year.

                I think I understand that you want the results in Excel. It's my assessment that the easiest way of accomplishing that would be to copy and paste the table from the Stata results window into Excel.
                Code:
                . sysuse auto, clear
                (1978 Automobile Data)
                
                . egen bygroups = group(foreign rep78), label
                (5 missing values generated)
                
                . ineqdeco price, by(bygroups)
                 
                [[[ intervening output deleted ]]]
                
                Subgroup indices: GE_k(a) and Gini_k
                
                -----------------------------------------------------------------------
                group(fore |
                ign rep78) |     GE(-1)       GE(0)       GE(1)       GE(2)        Gini
                -----------+-----------------------------------------------------------
                Domestic 1 |    0.00330     0.00329     0.00328     0.00328     0.04048
                Domestic 2 |    0.09696     0.10614     0.12448     0.15739     0.24586
                Domestic 3 |    0.11674     0.11882     0.12844     0.14785     0.26851
                Domestic 4 |    0.03164     0.03124     0.03155     0.03256     0.14063
                Domestic 5 |    0.00138     0.00138     0.00138     0.00138     0.02622
                 Foreign 3 |    0.02179     0.02219     0.02280     0.02363     0.11045
                 Foreign 4 |    0.04081     0.03982     0.03980     0.04076     0.15974
                 Foreign 5 |    0.07218     0.07305     0.07738     0.08585     0.21065
                         . |                                                          
                -----------------------------------------------------------------------
                
                [[[ remaining output deleted ]]]
                I will also say that with sufficient Stata expertise it's possible to do this more elegantly, looping over the data to compute each coefficient one-at-a-time and posting the results to an Excel spreadsheet. For a new user, the copy-and-paste route will get your results into Excel fastest.

                Comment


                • #9
                  Originally posted by Stan Breetman View Post
                  I have already read in google and forums about these comands.
                  I would recommend that you start with Stata's own documentation, including the help files and PDF documents. Most user-written packages for Stata, such as those found with findit gini, also come with a help file that explains how they should be used. For the packages mentioned by Carlo and William, you can read the help files with the following commands:
                  Code:
                  help descogini
                  help ineqdeco

                  Comment


                  • #10
                    Thank you very much everybody.

                    I think I will try the way Mr. Lisowski and Carlos told me with ineqdeco.

                    Mr. Lisowski did you use the 'GINIDESC' module to install? Because there are several modules. I think thats the good one, but I would be happy if i get a confirmation.

                    Comment


                    • #11
                      Hi all,

                      I have to say it worked well with the suggestion of Mr. Lisowski. Thank you very much for everybody. I checked the Gini Coeffiecients and they seem to be correct what makes me happy .

                      Following steps to do for my mentioned problem:
                      1. Download 'GINIDESC' module
                      2. Follow the comands by William Lisowski
                      3. Copying the Gini Coefficients into Excel is very easy and you can sort them later as you want.

                      Kind regards,

                      Stan

                      Comment


                      • #12
                        Actually, what I downloaded was the ineqdeco package returned as the fourth item from search ineqdeco.
                        Code:
                        ineqdeco from http://fmwww.bc.edu/RePEc/bocode/i
                            'INEQDECO': module to calculate inequality indices with decomposition by
                            subgroup / ineqdeco estimates a range of inequality and related / indices
                            commonly used by economists, plus optional / decompositions of a subset of
                            these indices by population / subgroup.  Indices estimated are:  members
                        But the good news is that the ginidesc package uses, and downloads, the ineqdeco command, so you got what you needed.

                        Comment


                        • #13
                          Originally posted by William Lisowski View Post
                          In the made-up example below inspired by Carlo's post I use the user-written ineqdeco command to calculate "gini coefficients" for price in the auto dataset, separate for each combination of foreign/domestic and reputation(1 to 5). This is similar to calculating the gini coefficient for wage separately for each combination of team and year.

                          I think I understand that you want the results in Excel. It's my assessment that the easiest way of accomplishing that would be to copy and paste the table from the Stata results window into Excel.
                          Code:
                          . sysuse auto, clear
                          (1978 Automobile Data)
                          
                          . egen bygroups = group(foreign rep78), label
                          (5 missing values generated)
                          
                          . ineqdeco price, by(bygroups)
                          
                          [[[ intervening output deleted ]]]
                          
                          Subgroup indices: GE_k(a) and Gini_k
                          
                          -----------------------------------------------------------------------
                          group(fore |
                          ign rep78) | GE(-1) GE(0) GE(1) GE(2) Gini
                          -----------+-----------------------------------------------------------
                          Domestic 1 | 0.00330 0.00329 0.00328 0.00328 0.04048
                          Domestic 2 | 0.09696 0.10614 0.12448 0.15739 0.24586
                          Domestic 3 | 0.11674 0.11882 0.12844 0.14785 0.26851
                          Domestic 4 | 0.03164 0.03124 0.03155 0.03256 0.14063
                          Domestic 5 | 0.00138 0.00138 0.00138 0.00138 0.02622
                          Foreign 3 | 0.02179 0.02219 0.02280 0.02363 0.11045
                          Foreign 4 | 0.04081 0.03982 0.03980 0.04076 0.15974
                          Foreign 5 | 0.07218 0.07305 0.07738 0.08585 0.21065
                          . |
                          -----------------------------------------------------------------------
                          
                          [[[ remaining output deleted ]]]
                          I will also say that with sufficient Stata expertise it's possible to do this more elegantly, looping over the data to compute each coefficient one-at-a-time and posting the results to an Excel spreadsheet. For a new user, the copy-and-paste route will get your results into Excel fastest.
                          Respected Sir
                          I was using these commands and i studied help comands as well,actually i have four provinces and 20 years data for each province and i wan to calculate yearly data for each province.but when i enter comands i either be sucessful in getting yearly data or just for provinces as whole.my variable is GDPPC and i want to calculate weighted gini GDPPC for each province and for every year.i want to get the results so that i copy it in excel.

                          i do this my id and year i got zero results
                          ----------------------------------------------------------------------
                          group(id |
                          year) | GE(-1) GE(0) GE(1) GE(2) Gini
                          ----------+-----------------------------------------------------------
                          1 1990 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1991 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1992 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1993 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1994 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1995 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1996 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1997 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1998 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          1 1999 | 0.00000 0.00000 0.00000 0.00000 0.00000
                          if i do this by just year i got

                          Subgroup indices: GE_k(a) and Gini_k

                          ----------------------------------------------------------------------
                          group(yea |
                          r) | GE(-1) GE(0) GE(1) GE(2) Gini
                          ----------+-----------------------------------------------------------
                          1990 | 0.31453 0.22186 0.18524 0.17825 0.32842
                          1991 | 0.31402 0.22168 0.18519 0.17827 0.32841
                          1992 | 0.31351 0.22150 0.18515 0.17830 0.32840
                          1993 | 0.31300 0.22132 0.18510 0.17832 0.32839
                          1994 | 0.31249 0.22114 0.18505 0.17834 0.32838
                          1995 | 0.31199 0.22096 0.18501 0.17837 0.32837
                          1996 | 0.31148 0.22078 0.18496 0.17839 0.32837
                          1997 | 0.31098 0.22060 0.18492 0.17842 0.32836
                          1998 | 0.31786 0.22578 0.19016 0.18482 0.33316
                          but i want gini for each province and for each year

                          i would be thanful if you help me.

                          Regards
                          qurat ul ain
                          Last edited by Qurat ul Ain; 29 Jan 2019, 23:32.

                          Comment


                          • #14
                            [no access to Stata, so guessing syntax]

                            egen year_pr = groups(year province), labels
                            statsby gini = r(gini), by(year_pr) saving(output.dta, replace): ineqdeco percapita_income
                            *now you have a Stata dataset
                            use output.dta, clear
                            export excel <...>

                            Comment


                            • #15
                              Originally posted by Stephen Jenkins View Post
                              [no access to Stata, so guessing syntax]

                              egen year_pr = groups(year province), labels
                              statsby gini = r(gini), by(year_pr) saving(output.dta, replace): ineqdeco percapita_income
                              *now you have a Stata dataset
                              use output.dta, clear
                              export excel <...>
                              Respected sir

                              I have data in stata and i make subgroups by egen still the results are zero for year and provincebut when i calculate it only for year it gives me the results.

                              Subgroup indices: GE_k(a) and Gini_k

                              ------------------------------------------------------------------------
                              group(provi |
                              nces year) | GE(-1) GE(0) GE(1) GE(2) Gini
                              ------------+-----------------------------------------------------------
                              Punjab 1990 | 0.00000 0.00000 0.00000 0.00000 0.00000
                              Punjab 1991 | 0.00000 0.00000 0.00000 0.00000 0.00000
                              Punjab 1992 | 0.00000 0.00000 0.00000 0.00000 0.00000
                              Punjab 1993 | 0.00000 0.00000 0.00000 0.00000 0.00000
                              Punjab 1994 | 0.00000 0.00000 0.00000 0.00000 0.00000
                              Punjab 1995 | 0.00000 0.00000 0.00000 0.00000 0.00000
                              Punjab 1996 | 0.00000 0.00000 0.00000 0.00000 0.00000

                              Last edited by Qurat ul Ain; 30 Jan 2019, 03:14.

                              Comment

                              Working...
                              X