Announcement

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

  • I need help running an ineqdeco code

    I'm trying to run code from a paper to replicate results, but I keep on running into an issue.

    I keep getting the feedback that r(gini) is missing for the entire code and my suspicion is that either Stata keeps trying to run ineqdeco for all of the variables at once or that ineqdeco doesn't actually store the results in r(), but I can't seem to make any headway. The excel sheet gives Gini indices on a different page, so I thought making a query to turn the data and gini indices into one worksheet would help. It hasn't changed the error message and that's the only modification I've done. I'm very much a novice at this and any help would be appreciated. Thank you!

    The code is below and in the excel everything listed in foreach is a variable:

    Code:
    *Figure 1
    . prog define Programma, rclass
      1. ineqdeco distribution
      2. ret scalar gini= $S_gini
      3. ret scalar ge0 = $S_i0
      4. end
    
    import excel "C:\Users\evang\Downloads\DataFigures.xlsx", sheet("Fig1(GINI+REG)") firstrow clear
    foreach distribution in SantaMariaImpruneta1307 SantaMariaImpruneta1319 SantaMariaImpruneta1330 SantaMariaImpruneta1350 SantaMariaImpruneta1365 SantaMariaImpruneta1373 SantaMariaImpruneta1384 SantaMariaImpruneta1395 SantaMariaImpruneta1402 SantaMariaImpruneta1414 SantaMariaImpruneta1427            Prato1325 Prato1356 Prato1365 Prato1373 Prato1394 Prato1402 Prato1414 Prato1428  {
    
    dis "Analyzing `distribution'"
    
    gen distribution =`distribution'
    
    sum distribution, detail
    
    drop if distribution<=0
    
    ineqdeco distribution
    
    bootstrap gini = r(gini), reps(200): Programma
    
    drop distribution
    
    }
    program drop Programma

  • #2
    The most likely scenario is that you are not defining the globals: $S_gini or $S_i0

    Comment


    • #3
      I can't access your spreadsheet, unsurprisingly, and I won't try to reproduce results from your program, as it seems pointless. Perhaps the paper (no reference given) was written for a much earlier version of ineqdeco, or whoever wrote it had a limited grasp of what was possible.

      ineqdeco from SSC defines r(gini) any way, so you can bootstrap directly. Here is a token run.

      Code:
      . clear
      
      . set obs 100 
      Number of observations (_N) was 0, now 100.
      
      . set seed 314159265 
      
      . gen distribution = exp(rnormal(1, 1))
      
      . su distribution, detail 
      
                              distribution
      -------------------------------------------------------------
            Percentiles      Smallest
       1%     .3583628       .1676061
       5%     .7451121       .5491195
      10%      1.09246       .6846856       Obs                 100
      25%      1.73173       .7179138       Sum of wgt.         100
      
      50%     3.181048                      Mean           4.928211
                              Largest       Std. dev.      5.395707
      75%     5.488293       21.27732
      90%     12.52368       21.61281       Variance       29.11366
      95%     18.58195       23.30568       Skewness       2.251534
      99%     25.44184       27.57799       Kurtosis       7.873677
      
      . 
      . ineqdeco distribution
       
      Percentile ratios
      
      ----------------------------------------------------------
        All obs |    p90/p10     p90/p50     p10/p50     p75/p25
      ----------+-----------------------------------------------
                |     11.464       3.937       0.343       3.169
      ----------------------------------------------------------
        
      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.69372     0.43679     0.43279     0.59337     0.49664
      ----------------------------------------------------------------------
         
      Atkinson indices, A(e), where e > 0 is the inequality aversion parameter
      
      ----------------------------------------------
        All obs |     A(0.5)        A(1)        A(2)
      ----------+-----------------------------------
                |    0.19708     0.35389     0.58114
      ----------------------------------------------
      
      . 
      . bootstrap gini = r(gini), reps(200): ineqdeco distribution 
      (running ineqdeco on estimation sample)
      
      warning: ineqdeco does not set e(sample), so no observations will be excluded from
               the resampling because of missing values or other reasons. To exclude
               observations, press Break, save the data, drop any observations that are
               to be excluded, and rerun bootstrap.
      
      Bootstrap replications (200)
      ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
      ..................................................    50
      ..................................................   100
      ..................................................   150
      ..................................................   200
      
      Bootstrap results                                          Number of obs = 100
                                                                 Replications  = 200
      
            Command: ineqdeco distribution
               gini: r(gini)
      
      ------------------------------------------------------------------------------
                   |   Observed   Bootstrap                         Normal-based
                   | coefficient  std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
              gini |   .4966397   .0260636    19.05   0.000     .4455559    .5477235
      ------------------------------------------------------------------------------

      Comment


      • #4
        FernandoRios ineqdeco defines global S_gini

        Comment


        • #5
          I ran the code again and realized ineqdeco distribution again and realized that the values it gave me are the same whether or not I include the foreach term indicating the variables. This paper is recent and, though they do some work on Excel, they seem to run it on Stata. Does any of this information help?

          Also fair point Nick Cox, I kind of blanked on giving information. I'm attaching the excel below and the paper is from the American Economics forum on the historical effect of pandemics on wages and income inequality. The link is here: https://www.aeaweb.org/articles?id=10.1257/jel.20201640.
          Attached Files

          Comment


          • #6
            Thanks for being willing to post data but please see https://www.statalist.org/forums/help#stata for why spreadsheet files are deprecated here.

            Perhaps your project is reproducing exactly what the author did. My interest would be limited to getting results for each variable, which seems to allow simplified code, as follows, except that I have not tested it.

            Note that your drop of zero or negative values is dangerous as dropping observations you don't want for one variable could delete observations you do want for another variable. If the paper author did that, watch out.


            Code:
            import excel "C:\Users\evang\Downloads\DataFigures.xlsx", sheet("Fig1(GINI+REG)") firstrow clear
            
            foreach distribution in SantaMariaImpruneta1307 SantaMariaImpruneta1319 SantaMariaImpruneta1330 SantaMariaImpruneta1350 SantaMariaImpruneta1365 SantaMariaImpruneta1373 SantaMariaImpruneta1384 SantaMariaImpruneta1395 SantaMariaImpruneta1402 SantaMariaImpruneta1414 SantaMariaImpruneta1427            Prato1325 Prato1356 Prato1365 Prato1373 Prato1394 Prato1402 Prato1414 Prato1428  {
            
            dis "Analyzing `distribution'"
            
            sum `distribution', detail
            
            ineqdeco `distribution' if `distribution' > 0 
            
            bootstrap gini = r(gini), reps(200): ineqdeco `distribution' if `distribution' > 0 
            
            }

            Comment


            • #7
              I wanted to update this post with my end results for anyone who runs across it in the future.

              I ended up bootstrapping each individual variable with the ineqdeco command (the code I used was bootstrap gini = r(gini), reps(200): ineqdeco [varname]) and it worked exactly as needed, but obviously this strategy is less plausible for larger numbers of variables. While I was working on this code, I did identify the problem with it though I don't know enough to diagnose or solve it: the distribution variable produces only missing values, which is why the gini indices are the same as if there is no variable present and if you specify `distribution' < . the bootstrap line will give an error saying that there are no observations. If you are seeing this in the future, I hope it can help some.

              Thanks also to Nick Cox and Fernando Rios for the help.

              Comment

              Working...
              X