Announcement

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

  • How to create a table out of values stored in local?

    Hello,

    I am computing Gini coefficients for different income distributions and want to create a simple table which shows the Gini coefficient for each respective distribution.

    I am currently using 7 distributions (c_1 till c_7), and using the command ineqdeco to compute Gini coefficients.
    This is the code I have written so far:
    Code:
        foreach i of numlist 1/7 {
        ineqdeco c_`i'
        local gini_`i' = r(gini)
        }    
        foreach i of numlist 1/7 {
        display `gini_`i''
        }
    I simply save the Gini as a unique local and then list all the Gini coefficients. However, I want to create a table with two columns (distribution & Gini coefficient) which shows the type of distribution and respective Gini in each row.

    I have never done something like this and my use of locals was my best guess as a starting point. I am not able to find a guide for this in the Stata manuals, since I do not know where to look.

    Could anyone help me or push me in the right direction?

    Thanks!

  • #2
    I typicaly do something like that by collecting the results in a matrix, and than use matlist to display that matrix.

    Code:
    matrix res = J(7,1,.)
    matrix colnames res = "Gini"
    matrix rownames res = "c_1" "c_2" "c_3" "c_4" "c_5" "c_6"  "c_7"
    
    foreach i of numlist 1/7 {
        ineqdeco c_`i'
        matrix res[i,1] = r(gini)
    }
    matlist res
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks, that works!

      Just a small typo correction for anyone interested in this code:

      Code:
      matrix res = J(7,1,.)
      matrix colnames res = "Gini"matrix rownames res = "c_1" "c_2" "c_3" "c_4" "c_5" "c_6" "c_7"
      
      foreach i of numlist 1/7 {
          ineqdeco c_`i'
          matrix res[`i',1] = r(gini)
      }
      matlist res

      Comment

      Working...
      X