Announcement

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

  • Combining information from two columns of a matrix into a variable

    Dear Statalist - users,

    I'm working with the package ginidesc that i installed from ssc to compute gini-coefficients for subpopulations within countries.

    Here are the commands I used and parts of the resulting output:

    Code:
    ginidesc income_equivalised if incrank_2 == 1, by(country) gk(i1)
    Code:
    Gini Coefficient by subgroups
    of country
    
    -----------------------------
                   K |     Gini_k
    -----------------+-----------
    Austria          |      0.298
    Belgium          |      0.228
    Bulgaria         |      0.270
    Cyprus           |      0.294
    Czech Republic  |  0.290
    Germany        |      0.330
    Denmark        |      0.284
    Estonia           |      0.222
    
    Stored in matrix i2
    I tried to store the Gini-coefficients in a variable with the following commands:

    Code:
    matrix list i1
    svmat i1, names(inc)
    This created 2 variables, one for each column, but the gini-coefficients are saved as the category and not the value of the variable. Also the information is now disconnected from the country - variable in the data set.

    Code:
    tab inc2
    
           inc2 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       .1230075 |          1        3.03        3.03
       .1402118 |          1        3.03        6.06
       .1471672 |          1        3.03        9.09
       .1478555 |          1        3.03       12.12
       .1688081 |          1        3.03       15.15
       .1694496 |          1        3.03       18.18
       .1719411 |          1        3.03       21.21
       .1736457 |          1        3.03       24.24
       .1751534 |          1        3.03       27.27
    I would greatly appreciate if someone could tell me how to create one variable that has the same gini-coefficient for each observation within a country. Thanks a lot in advance!










  • #2
    It is difficult to follow what you want as the output indicates that the Gini coefficients are stored in matrix i2 and you svmat matrix i1. Most people including myself do not use this command so I suggest that you do the following:


    Code:
    ginidesc income_equivalised if incrank_2 == 1, by(country) gk(i1)
    mat l i1 
    mat list i2
    clear
    svmat i1
    svmat i2
    dataex
    Then copy and paste the outputs of the matrix list commands and the dataex.

    Comment


    • #3
      Thank you for your reply Andrew. Indeed, I have mixed up the annotation. I have meant to only include the matrix i1.

      Here is the output to the commands you suggested:

      Code:
      . mat l i1
      
      i1[33,2]
                 k     Gini_k
      k         29  .38146576
      k         33  .36469457
      k         32  .30149865
      k         19  .28763977
      k         24  .24093089
      k         17  .28083768
      k          3  .26932833
      k         35   .2533761
      k          9  .24810015
      k         26  .19667381
      k         23   .2387253
      k          8  .23858768
      k         10  .20662333
      k         14  .20646381
      k         13   .2387725
      k         27   .1986126
      k         22  .21360622
      k         36  .18896493
      k          4  .19449703
      k         16   .2619614
      k         20  .20656714
      k          5   .1694496
      k         15   .1751534
      k         28  .18700944
      k         12  .16880809
      k         21  .22658722
      k          2   .1736457
      k          1  .18417412
      k          6  .14785549
      k          7  .17194112
      k         11  .14716721
      k         25  .14021179
      k         18  .12300753
      
      . clear
      
      . svmat i1
      number of observations will be reset to 33
      Press any key to continue, or Break to abort
      Number of observations (_N) was 0, now 33.
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(i11 i12)
      29  .3814658
      33  .3646946
      32 .30149865
      19 .28763977
      24  .2409309
      17 .28083768
       3 .26932833
      35  .2533761
       9 .24810015
      26  .1966738
      23  .2387253
       8 .23858768
      10 .20662333
      14  .2064638
      13  .2387725
      27  .1986126
      22 .21360622
      36 .18896493
       4 .19449703
      16  .2619614
      20 .20656714
       5  .1694496
      15  .1751534
      28 .18700944
      12  .1688081
      21  .2265872
       2  .1736457
       1  .1841741
       6 .14785549
       7  .1719411
      11  .1471672
      25 .14021179
      18 .12300753
      end

      Comment


      • #4
        but the gini-coefficients are saved as the category and not the value of the variable.
        I do not understand this statement. The variable i12 appears to be continuous to me and not a categorical variable. This will merge the country names with the matrix output.


        Code:
        preserve
        decode country, g(name)
        contract country name
        tempfile names
        save `names'
        restore
        ginidesc income_equivalised if incrank_2 == 1, by(country) gk(i1)
        mat l i1
        clear
        svmat i1
        rename (i11 i12) (country gini)
        merge 1:1 country using `names', nogen
        l, sep(0)

        Comment


        • #5
          Your approach has worked! Thank you so much, Andrew.
          What I meant with categorical is that the gini-coefficients after svmat were stored as the categories of a variable and not as the values or frequencies of it. Like here:

          Code:
           tab i12
          
                  i12 |      Freq.     Percent        Cum.
          ------------+-----------------------------------
             .1230075 |          1        3.03        3.03
             .1402118 |          1        3.03        6.06
             .1471672 |          1        3.03        9.09
             .1478555 |          1        3.03       12.12
             .1688081 |          1        3.03       15.15
             .1694496 |          1        3.03       18.18
             .1719411 |          1        3.03       21.21
             .1736457 |          1        3.03       24.24
             .1751534 |          1        3.03       27.27
             .1841741 |          1        3.03       30.30
             .1870094 |          1        3.03       33.33
             .1889649 |          1        3.03       36.36
              .194497 |          1        3.03       39.39
             .1966738 |          1        3.03       42.42
             .1986126 |          1        3.03       45.45
             .2064638 |          1        3.03       48.48
             .2065671 |          1        3.03       51.52
             .2066233 |          1        3.03       54.55
             .2136062 |          1        3.03       57.58
             .2265872 |          1        3.03       60.61
             .2385877 |          1        3.03       63.64
             .2387253 |          1        3.03       66.67
             .2387725 |          1        3.03       69.70
             .2409309 |          1        3.03       72.73
             .2481001 |          1        3.03       75.76
             .2533761 |          1        3.03       78.79
             .2619614 |          1        3.03       81.82
             .2693283 |          1        3.03       84.85
             .2808377 |          1        3.03       87.88
             .2876398 |          1        3.03       90.91
             .3014987 |          1        3.03       93.94
             .3646946 |          1        3.03       96.97
             .3814658 |          1        3.03      100.00
          ------------+-----------------------------------
                Total |         33      100.00

          Comment

          Working...
          X