Announcement

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

  • Create table to rank results of ineqdeco results

    Hello everyone,

    I'm new to Stata and this forum, so please forgive my lack of knowledge. I have to calculate different inequality measures for a given dataset (Gini, Atkinson, Theil, etc...) for different population categories. This is fairly simple to do with the ineqdeco package.
    With the different measures, some group rank differently (from most unequal to most equal). I have listed to difference in ranking simply by adding a comment in the do file, but I'd like to create a more elegant table that can automatically pick these differences in ranking. So I am imagining the population categories as the rows and the ranking order as the columns. Is there a way to do this by directly linking the ineqdeco results to this table, such that should the results change (becasue of changes to the dataset, let's say), then the ranking and the table would also automatically change?

    This is the ineqdeco command I'm using: ineqdeco incomepc [w=WT], by(ID13)
    * incomepc is my variable of interest
    * weighted by WT
    * and my population categories are ID13

    I hope my query is clear enough. I'm using the lastest version of Stata.

    Thank you for your time,

    Clara

  • #2
    The crux of your problem is that you need to save the results from ineqdeco to a dataset to make subsequent use of them. Here is an example that may start you in a useful direction, saving selected values from the "Saved results" described in the output of the help ineqdeco command.
    Code:
    sysuse auto, clear
    ineqdeco price, by(foreign)
    return list
    tempfile gnxl
    postfile results foreign ge2 gini using "`gnxl'"
    foreach f in `r(levels)' {
        post results (`f') (r(ge2_`f')) (r(gini_`f'))
    }
    postclose results
    use "`gnxl'", clear
    list, clean noobs
    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . ineqdeco price, by(foreign)
     
    Percentile ratios
    
    ----------------------------------------------------------
      All obs |    p90/p10     p90/p50     p10/p50     p75/p25
    ----------+-----------------------------------------------
              |      2.923       2.274       0.778       1.512
    ----------------------------------------------------------
      
    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.08199     0.08605     0.09557     0.11289     0.23222
    ----------------------------------------------------------------------
      
    Atkinson indices, A(e), where e > 0 is the inequality aversion parameter
    
    ----------------------------------------------
      All obs |     A(0.5)        A(1)        A(2)
    ----------+-----------------------------------
              |    0.04450     0.08245     0.14088
    ----------------------------------------------
      
    Subgroup summary statistics, for each subgroup k = 1,...,K:
      
    
    -------------------------------------------------------------------------------------
    Car       |
    origin    |   Popn. share           Mean  Relative mean   Income share      log(mean)
    ----------+--------------------------------------------------------------------------
     Domestic |       0.70270     6072.42308        0.98494        0.69212        8.71151
      Foreign |       0.29730     6384.68182        1.03559        0.30788        8.76166
    -------------------------------------------------------------------------------------
      
    Subgroup indices: GE_k(a) and Gini_k
    
    ----------------------------------------------------------------------
    Car       |
    origin    |     GE(-1)       GE(0)       GE(1)       GE(2)        Gini
    ----------+-----------------------------------------------------------
     Domestic |    0.08706     0.09293     0.10534     0.12756     0.23777
      Foreign |    0.06834     0.06892     0.07273     0.08049     0.21108
    ----------------------------------------------------------------------
      
    Within-group inequality, GE_W(a)
    
    ----------------------------------------------------------
      All obs |     GE(-1)       GE(0)       GE(1)       GE(2)
    ----------+-----------------------------------------------
              |    0.08173     0.08579     0.09530     0.11262
    ----------------------------------------------------------
                  
    Between-group inequality, GE_B(a):
    
    ----------------------------------------------------------
      All obs |     GE(-1)       GE(0)       GE(1)       GE(2)
    ----------+-----------------------------------------------
              |    0.00026     0.00026     0.00027     0.00027
    ----------------------------------------------------------
                  
    Subgroup Atkinson indices, A_k(e)
    
    ----------------------------------------------
    Car       |
    origin    |     A(0.5)        A(1)        A(2)
    ----------+-----------------------------------
     Domestic |    0.04848     0.08874     0.14829
      Foreign |    0.03488     0.06660     0.12025
    ----------------------------------------------
      
    Within-group inequality, A_W(e)
    
    ----------------------------------------------
      All obs |     A(0.5)        A(1)        A(2)
    ----------+-----------------------------------
              |    0.04429     0.08192     0.13966
    ----------------------------------------------
     
    Between-group inequality, A_B(e)
    
    ----------------------------------------------
      All obs |     A(0.5)        A(1)        A(2)
    ----------+-----------------------------------
              |    0.00022     0.00058     0.00142
    ----------------------------------------------
    
    . return list
    
    scalars:
                   r(ede2) =  5296.67182806118
                   r(ede1) =  5656.906729539464
                r(edehalf) =  5890.891413030665
             r(between_a2) =  .0014220371069532
             r(between_a1) =  .0005798637458023
          r(between_ahalf) =  .0002189045211914
              r(within_a2) =  .1396603860401734
              r(within_a1) =  .0819216302593577
           r(within_ahalf) =  .044292643337864
                   r(a2_1) =  .120251251326965
                   r(a1_1) =  .0665967017412186
                r(ahalf_1) =  .0348828885410051
                   r(a2_0) =  .148294201236304
                   r(a1_0) =  .0887386575341225
                r(ahalf_0) =  .0484784087085219
            r(between_ge2) =  .0002679535178404
            r(between_ge1) =  .0002661615119775
            r(between_ge0) =  .0002644106835199
           r(between_gem1) =  .0002627002691232
             r(within_ge2) =  .1126217670888891
             r(within_ge1) =  .0953009106877201
             r(within_ge0) =  .0857881439463363
            r(within_gem1) =  .0817307625025281
                 r(sumw_1) =  22
                    r(v_1) =  .2972972972972973
               r(lambda_1) =  1.035590579611236
                r(theta_1) =  .3078782804249621
               r(lgmean_1) =  8.761656934520458
                 r(mean_1) =  6384.681818181818
              r(gini_1) =  .2110814688824557
                  r(ge2_1) =  .0804869266037308
                  r(ge1_1) =  .072725769905224
                  r(ge0_1) =  .0689179088113295
                 r(gem1_1) =  .0683440877343363
                 r(sumw_0) =  52
                    r(v_0) =  .7027027027027027
               r(lambda_0) =  .9849424470875541
                r(theta_0) =  .692121719575038
               r(lgmean_0) =  8.711512993348268
                 r(mean_0) =  6072.423076923077
              r(gini_0) =  .2377725910959381
                  r(ge2_0) =  .1275629191851993
                  r(ge1_0) =  .1053430684872671
                  r(ge0_0) =  .0929255511188392
                 r(gem1_0) =  .0870571748199685
                     r(a2) =  .140883820895806
                     r(a1) =  .082453991337858
                  r(ahalf) =  .0445018519991732
                    r(ge2) =  .1128897206067294
                    r(ge1) =  .0955670721996976
                    r(ge0) =  .0860525546298563
                   r(gem1) =  .0819934627716512
                   r(gini) =  .2322248019945887
                 r(p75p50) =  1.266753220812943
                 r(p25p50) =  .8379107160691102
                 r(p10p50) =  .777988614800759
                 r(p90p50) =  2.274043743133926
                 r(p75p25) =  1.511799761620977
                 r(p90p10) =  2.922978177150192
                    r(p95) =  13466
                    r(p90) =  11385
                    r(p75) =  6342
                    r(p50) =  5006.5
                    r(p25) =  4195
                    r(p10) =  3895
                     r(p5) =  3748
                    r(max) =  15906
                    r(min) =  3291
                      r(N) =  74
                   r(sumw) =  74
                     r(sd) =  2949.495884768919
                    r(Var) =  8699525.97426879
                   r(mean) =  6165.256756756757
    
    macros:
                 r(levels) : "0 1"
    
    . tempfile gnxl
    
    . postfile results foreign ge2 gini using "`gnxl'"
    
    . foreach f in `r(levels)' {
      2.     post results (`f') (r(ge2_`f')) (r(gini_`f'))
      3. }
    
    . postclose results
    
    . use "`gnxl'", clear
    
    . list, clean noobs
    
     foreign        ge2       gini  
              0   .1275629   .2377726  
              1   .0804869   .2110815  
    
    .
    Last edited by William Lisowski; 23 Oct 2021, 10:45. Reason: Replaced forvalues using hardcoded values with foreach using r(levels)

    Comment

    Working...
    X