Announcement

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

  • My Lorenz curves are coming out as straight lines.

    Hello Stata Experts,

    I am trying to create lorenz curves for a variable with four categories. I have done this before but this time my curves are coming out as straight lines. I am sharing an example dataset along with my commands.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float raw_rank1 byte v190 float(sei z) double rank float rank2
    1519 2  -.57867503 0 .438 .438
    1521 2  -.57797277 0 .439 .439
     890 1   -.8061847 0 .273 .273
    2461 2 .0007149702 0 .655 .655
    2061 2  -.28932393 0  .56  .56
    2988 3    .4960965 0 .763 .763
    1394 2   -.6336712 0 .407 .407
     119 1  -1.0780907 0 .045 .045
    1511 2   -.5812709 0 .435 .435
     158 1  -1.0511917 0 .057 .057
    3132 3    .6742755 0 .805 .805
    1028 1   -.7624822 0 .311 .311
    1493 2   -.5876991 0 .431 .431
    1592 2   -.5417551 0 .451 .451
    3225 3    .8141427 0 .822 .822
    1406 2   -.6303535 0 .409 .409
    1921 2   -.3819044 0 .526 .526
     266 1  -1.0056158 0 .092 .092
    2282 2  -.14398591 0 .611 .611
      11 1   -1.223736 0 .001 .001
      66 1  -1.1141272 0 .027 .027
    3905 3    2.594721 0 .983 .983
    1562 2   -.5555258 0 .446 .446
     212 1  -1.0261097 0 .075 .075
     277 1  -1.0024703 0 .098 .098
    3750 3   1.9207685 0 .949 .949
     114 1   -1.080746 0 .044 .044
     414 1   -.9529806 0 .141 .141
    1021 1   -.7646693 0 .308 .308
    3956 3    2.976368 0 .992 .992
    2139 2   -.2403019 0 .576 .576
     872 1   -.8127694 0 .267 .267
    1201 1   -.7066278 0 .357 .357
      42 1  -1.1533086 0 .019 .019
    1211 1   -.7038143 0 .359 .359
     673 1   -.8647565 0 .215 .215
      61 1   -1.119929 0 .024 .024
    2684 3    .1753951 0   .7   .7
    2035 2   -.3084227 0 .552 .552
    1706 2   -.4945633 0 .477 .477
     106 1  -1.0862021 0 .041 .041
     445 1   -.9433951 0  .15  .15
    3025 3   .53929883 0 .775 .775
    3368 3   1.0676816 0 .868 .868
    2483 2  .011977144 0 .658 .658
    1341 2   -.6609402 0 .392 .392
     123 1    -1.07341 0 .047 .047
    3627 3   1.5838754 0 .929 .929
     942 1   -.7906448 0 .286 .286
    2722 3   .20741607 0  .71  .71
    3233 3    .8326448 0 .823 .823
    1628 2  -.52488875 0 .461 .461
    2923 3    .4188752 0 .753 .753
    3454 3   1.2099286 0  .89  .89
    1757 2   -.4668162 0 .489 .489
    1435 2   -.6137782 0 .416 .416
    2478 2  .008811969 0 .657 .657
    3957 3     2.99273 0 .993 .993
    1430 2   -.6182839 0 .414 .414
     964 1   -.7837582 0 .292 .292
    1427 2   -.6187509 0 .412 .412
     927 1    -.795358 0 .282 .282
    1634 2   -.5228623 0 .463 .463
     645 1   -.8762712 0 .206 .206
    3474 3    1.252518 0 .894 .894
    2442 2 -.012976546 0  .65  .65
     735 1   -.8494613 0 .237 .237
    1143 1   -.7286108 0 .345 .345
    2302 2   -.1215786 0 .617 .617
    1652 2   -.5176178 0 .467 .467
     561 1   -.9010396 0 .187 .187
    3317 3    .9688857 0 .854 .854
      73 1  -1.1084094 0  .03  .03
    3866 3   2.3716063 0 .973 .973
     319 1   -.9914252 0  .11  .11
    2440 2 -.013812775 0 .649 .649
      26 1  -1.1747433 0 .012 .012
     258 1  -1.0091702 0 .089 .089
    1556 2   -.5576935 0 .445 .445
     322 1    -.990563 0 .112 .112
    2132 2  -.24586444 0 .574 .574
     801 1   -.8318206 0 .254 .254
     711 1    -.856173 0 .229 .229
    2699 3   .19003813 0 .705 .705
    3192 3    .7619695 0 .819 .819
    1226 1   -.6974397 0 .365 .365
    1607 2  -.53420997 0 .454 .454
    3172 3      .72391 0 .812 .812
    2609 2   .10445177 0 .685 .685
    1983 2   -.3496844 0  .54  .54
    3392 3   1.1001801 0 .874 .874
    3078 3    .6023574 0 .789 .789
     734 1   -.8496683 0 .236 .236
    1976 2   -.3590761 0 .537 .537
    2136 2  -.24302575 0 .575 .575
    2604 2   .10296789 0 .682 .682
      17 1  -1.1979523 0 .006 .006
    1433 2   -.6150438 0 .415 .415
    1774 2    -.454978 0 .496 .496
    3412 3   1.1337353 0 .879 .879
    end
    label values v190 wlth
    Code:
    pca x1-x74
    predict comp1
    rename comp1 v191
    
    regr y v191 i.z        
    drop if e(sample)!=1 
    glcurve y , pvar(rank) glvar(Lorenz) sortvar(v191) replace by(z) split saving(v191_graph)

    I also tried using a standardized wealth index but it is not working either.
    Code:
    egen sei=std(v191)
    regr y sei i.z        
    drop if e(sample)!=1 
    glcurve y , pvar(rank) glvar(Lorenz) sortvar(sei) replace by(z) split saving(sei_graph)
    I will really appreciate any insight into this-where I am going wrong or what does this mean? I can share my full PCA code and the related data, if needed.

    Thanks in advance
    Deepali
    v191_graph.gphsei_graph.gph
    Deepali Godha

  • #2
    I can't see any clear connection between your code and your example data.

    Comment


    • #3
      Oh! My results have come from the original full dataset. I tried doing the same with an example dataset but then I am getting different results. I am not sure how to resolve this. Please suggest.
      Deepali Godha

      Comment


      • #4
        You need to present example data, precise code and those results that puzzle you so that we can see what is going on. My guess is that you are not giving glcurve (from the Stata Journal and SSC) all the information it needs.

        Comment


        • #5
          Hello Nick,

          I am sharing a bigger data and the results I am getting from the same using the commands below. I am still not getting the curved lines that come with Lorenz graphs. I guess the lines are staggered because of lesser number of values but they are straight, not curved. Please advise what particular information I am not giving to glcurve. My data does not have weights, so that is not there.
          Code:
          input float(z y v191 sei)
          0 0 -1.8005377  -.57867503
          0 1 -1.7983526  -.57797277
          0 0   -2.50843   -.8061847
          0 0 .002224617   .00071497
          0 0  -.9002266  -.28932393
          0 0   1.543596    .4960965
          0 0 -1.9716575   -.6336712
          0 0  -3.354461  -1.0780907
          0 1 -1.8086146   -.5812709
          0 1 -3.2707655  -1.0511917
          0 1   2.097997    .6742755
          0 0 -2.3724508   -.7624822
          0 0  -1.828616   -.5876991
          0 0  -1.685662   -.5417551
          0 1  2.5331914    .8141427
          0 1 -1.9613343   -.6303535
          0 0 -1.1882893   -.3819044
          0 1  -3.128957  -1.0056158
          0 0  -.4480098  -.14398591
          0 1  -3.807634   -1.223736
          0 0  -3.466588  -1.1141272
          0 1   8.073432    2.594721
          0 1 -1.7285092   -.5555258
          0 1  -3.192723  -1.0261097
          0 0 -3.1191695  -1.0024703
          0 1   5.976439   1.9207685
          0 1  -3.362723   -1.080746
          0 1  -2.965183   -.9529806
          0 0 -2.3792558   -.7646693
          0 0    9.26092    2.976368
          0 1  -.7476953   -.2403019
          0 0 -2.5289185   -.8127694
          0 1 -2.1986609   -.7066278
          0 0 -3.5885005  -1.1533086
          0 0 -2.1899066   -.7038143
          0 1  -2.690675   -.8647565
          0 0 -3.4846404   -1.119929
          0 0  .54573894    .1753951
          0 1  -.9596521   -.3084227
          0 0 -1.5388255   -.4945633
          0 1    -3.3797  -1.0862021
          0 0  -2.935358   -.9433951
          0 1  1.6780194   .53929883
          0 0   3.322073   1.0676816
          0 0  .03726668  .011977144
          0 1 -2.0565042   -.6609402
          0 1 -3.3398974    -1.07341
          0 1   4.928202   1.5838754
          0 0  -2.460078   -.7906448
          0 1   .6453717   .20741607
          0 1  2.5907605    .8326448
          0 0 -1.6331826  -.52488875
          0 1   1.303323    .4188752
          0 1   3.764673   1.2099286
          0 0 -1.4524908   -.4668162
          0 0 -1.9097606   -.6137782
          0 1 .027418295  .008811969
          0 1    9.31183     2.99273
          0 0   -1.92378   -.6182839
          0 1 -2.4386506   -.7837582
          0 0  -1.925233   -.6187509
          0 1  -2.474743    -.795358
          0 0 -1.6268774   -.5228623
          0 1 -2.7265034   -.8762712
          0 1  3.8971896    1.252518
          0 1  -.0403763 -.012976546
          0 0 -2.6430845   -.8494613
          0 0 -2.2670603   -.7286108
          0 1  -.3782898   -.1215786
          0 1 -1.6105592   -.5176178
          0 1   -2.80357   -.9010396
          0 0   3.014672    .9688857
          0 1 -3.4487975  -1.1084094
          0 1   7.379214   2.3716063
          0 0  -3.084803   -.9914252
          0 0 -.04297822 -.013812775
          0 0  -3.655194  -1.1747433
          0 0  -3.140016  -1.0091702
          0 1  -1.735254   -.5576935
          0 0   -3.08212    -.990563
          0 0  -.7650031  -.24586444
          0 1  -2.588196   -.8318206
          0 1  -2.663968    -.856173
          0 0   .5913005   .19003813
          0 1  2.3708553    .7619695
          0 1  -2.170072   -.6974397
          0 1 -1.6621854  -.53420997
          0 1   2.252434      .72391
          0 0   .3249999   .10445177
          0 0 -1.0880373   -.3496844
          0 1   3.423192   1.1001801
          0 1   1.874225    .6023574
          0 0  -2.643729   -.8496683
          0 1 -1.1172593   -.3590761
          0 0  -.7561706  -.24302575
          0 0   .3203829   .10296789
          0 0 -3.7274084  -1.1979523
          0 0 -1.9136987   -.6150438
          0 1 -1.4156563    -.454978
          0 0  3.5275984   1.1337353
          1 1   3.602549  1.1578238
          1 0  -2.397197  -.7704353
          1 0 -2.5572336  -.8218696
          1 1   1.283576   .4125286
          1 1 -1.2850264  -.4129948
          1 0  -3.013025  -.9683565
          1 1 -1.8561542  -.5965496
          1 1  -2.580811  -.8294472
          1 0 -1.6965895  -.5452671
          1 1   2.656691   .8538343
          1 0   6.597354  2.1203244
          1 1 -2.0619106  -.6626777
          1 1  -2.633444  -.8463628
          1 0 -1.2708738  -.4084463
          1 1 -2.8787484  -.9252013
          1 1  -2.339422  -.7518671
          1 1   .8523463  .27393568
          1 1    7.00687  2.2519388
          1 1  -2.280661  -.7329819
          1 0 -2.3689153   -.761346
          1 1   4.640321  1.4913533
          1 0  -2.665193  -.8565667
          1 1 -3.8551755 -1.2390153
          1 1 -1.7708936  -.5691477
          1 1 -2.0495548  -.6587067
          1 1  -1.779485 -.57190895
          1 0    -2.7093  -.8707422
          1 1 -1.7077644  -.5488586
          1 1  -.9998189  -.3213319
          1 1    -1.3183  -.4236886
          1 1  -2.070613  -.6654745
          1 1  3.0200806    .970624
          1 1    3.55555  1.1427187
          1 1   .8288999  .26640025
          1 1 -2.1682966  -.6968691
          1 1 -1.5338597  -.4929674
          1 0   6.431994  2.0671792
          1 1  -3.194292  -1.026614
          1 0 -.17325315 -.05568185
          1 0  2.2915783   .7364906
          1 0  -2.259538  -.7261932
          1 0  -3.410865 -1.0962182
          1 1  -2.838278  -.9121946
          1 1 -1.7367936  -.5581883
          1 0  1.4428525   .4637185
          1 0 -2.6327474   -.846139
          1 0   .5147447  .16543385
          1 1 -.27424818 -.08814066
          1 0 -1.9144908  -.6152984
          1 1  .09709117  .03120414
          1 1  -3.704611 -1.1906253
          1 1  .12690374  .04078561
          1 0 -2.5070386  -.8057374
          1 1  4.6390457  1.4909434
          1 0   1.246669   .4006671
          1 1 -1.4754487 -.47419465
          1 0  -3.724996  -1.197177
          1 1  -1.752938  -.5633769
          1 1  3.8218746  1.2283127
          1 1   5.622064  1.8068757
          1 1  -1.291468 -.41506505
          1 1   2.397024   .7703797
          1 0  -3.296239 -1.0593785
          1 1   -3.57533 -1.1490759
          1 1   2.873277   .9234429
          1 1   5.843688  1.8781034
          1 1  -.7071175 -.22726057
          1 1 -3.0442245  -.9783837
          1 1   .6286101  .20202906
          1 1  -1.349846  -.4338272
          1 0 -2.8902414   -.928895
          1 1   .7935654  .25504407
          1 0  -1.359396  -.4368964
          1 0 -3.1050816  -.9979425
          1 1   -1.99407  -.6408744
          1 1  4.1306925  1.3275638
          1 0 -1.9668837   -.632137
          1 1 -2.3590555  -.7581772
          1 0  -2.477075  -.7961075
          1 1 -2.6929235   -.865479
          1 0    -.84017 -.27002233
          1 1  2.0061893   .6447694
          1 1   .7204221  .23153657
          1 0   2.992001   .9615996
          1 1   -3.17936  -1.021815
          1 0  -2.866496  -.9212636
          1 0  .20223545  .06499647
          1 1   6.161069   1.980107
          1 1   -.572112 -.18387115
          1 1  -2.592331  -.8331495
          1 1  3.9359844  1.2649865
          1 0 -2.6799724  -.8613167
          1 0    3.27631  1.0529736
          1 0  -3.120855  -1.003012
          1 1  -2.213926   -.711534
          1 0 -3.0686414   -.986231
          1 0  -2.523871  -.8111471
          1 1  -1.899604  -.6105139
          1 0   1.994619   .6410509
          1 1   -1.88694  -.6064439
          2 1    5.324709     1.711309
          2 1  -2.3621798    -.7591813
          2 1   -2.572101    -.8266479
          2 1    .8222409     .2642601
          2 1    2.587003     .8314373
          2 0    -3.16195   -1.0162196
          2 1 -.014003167 -.0045004794
          2 0   -.4303906   -.13832329
          2 1   2.3719304      .762315
          2 1  -1.1233517    -.3610341
          2 1  -.24548706   -.07889712
          2 1    4.490045     1.443056
          2 1  -1.8941617    -.6087648
          2 0  -2.0626082    -.6629019
          2 1  -1.2839516    -.4126494
          2 1  -1.1433952    -.3674759
          2 1   -1.886925    -.6064391
          2 1   1.4211794      .456753
          2 1   -1.941018    -.6238241
          2 1   -2.577832    -.8284898
          2 1    -2.89303    -.9297912
          2 1   2.4241774     .7791067
          2 0     .102885    .03306622
          2 1  -2.8437555    -.9139549
          2 0  -1.5825722   -.50862306
          2 0    -2.64955    -.8515393
          2 1  -3.4474995   -1.1079923
          2 0   2.3346908     .7503465
          2 0   2.8126316      .903952
          2 1   -2.401852    -.7719315
          2 1   10.427603    3.3513286
          2 0   -.5271367    -.1694165
          2 0    2.219329     .7132704
          2 1    6.825594    2.1936784
          2 1   -.8167692   -.26250154
          2 1   -2.018318    -.6486675
          2 1   -1.248242    -.4011726
          2 0  -2.2684135    -.7290457
          2 0   3.5813966    1.1510254
          2 1  -1.2571772    -.4040443
          2 1  -3.0543215    -.9816288
          2 1    7.990438     2.568048
          2 0  -.03201191  -.010288312
          2 0  -2.2488956    -.7227728
          2 0  -1.5385835    -.4944855
          2 1   -.5940833    -.1909325
          2 1    2.125286     .6830459
          2 1    .9916727     .3187138
          2 0    .2627518    .08444583
          2 1  -.13505468   -.04340524
          2 1  -2.1682067    -.6968402
          2 0   -2.818093    -.9057072
          2 1    .9941368     .3195057
          2 0    5.006502      1.60904
          2 0  -.27034932    -.0868876
          2 1  -1.8673595    -.6001509
          2 0    .6811582     .2189175
          2 0   -2.131762    -.6851273
          2 1    7.865067     2.527755
          2 1   -1.764499    -.5670925
          2 1    .4873916    .15664284
          2 1  -2.6645055    -.8563457
          2 1   -1.922058    -.6177305
          2 1    .3278699    .10537414
          2 1    1.825123    .58657646
          2 1  -1.6968967    -.5453658
          2 1   -1.241491     -.399003
          2 0  -2.7378676    -.8799236
          2 1  -1.0346314    -.3325203
          2 1   -3.643539   -1.1709975
          2 0   -2.582922    -.8301256
          2 1  -1.0430399    -.3352227
          2 0  -2.7388816    -.8802495
          2 1    .6132901     .1971054
          2 1  -1.3974004    -.4491107
          2 1  -1.8465933   -.59347683
          2 1   -2.487416    -.7994309
          2 1    6.095332    1.9589794
          2 0   2.3875465     .7673339
          2 1 -.009368427   -.00301092
          2 1    .5249772     .1687225
          2 1     3.78108     1.215202
          2 1  -1.3284963    -.4269656
          2 1   -3.224134   -1.0362048
          2 1  -2.7144134    -.8723856
          2 0   -.9141977   -.29381412
          2 1    3.322918    1.0679531
          2 0    5.861701     1.883893
          2 1  -2.2875266    -.7351884
          2 1   3.1591985    1.0153352
          2 0  -1.7692137    -.5686078
          2 1    4.795874    1.5413465
          2 1    9.959199     3.200788
          2 1    -3.04138    -.9774694
          2 0  -2.2961211    -.7379506
          2 0    9.250632     2.973062
          2 1   1.1370308     .3654305
          2 0   -1.387308    -.4458671
          2 0   -2.983903     -.958997
          2 0   3.9393344     1.266063
          end
          My Stata commands:
          Code:
          *Creating PCA
          pca x1-x70
          predict comp1
          rename comp1 v191
          
          *Lorenz curve with PCA
          regr y v191 i.z        
          drop if e(sample)!=1 
          glcurve y , pvar(rank) glvar(Lorenz) sortvar(v191) replace by(z) split saving(v191_graph)
          
          *Lorenz curve with standardized PCA
          egen sei=std(v191)
          regr y sei i.z        
          drop if e(sample)!=1 
          glcurve y , pvar(rank) glvar(Lorenz) sortvar(sei) replace by(z) split saving(sei_graph)
          My graphs are attached.v191_graph.gphsei_graph.gph

          I am also attaching my PCA output for the first 10 components. I have 30 components with an Eigenvalue greater than 1 but I am assuming that 12.57% is not bad (though not good either).
          HTML Code:
          Principal components/correlation    Number of obs    =      4,000
              Number of comp.    =         70
              Trace    =         77
          Rotation: (unrotated = principal)    Rho    =     1.0000
          
                  
          Component    Eigenvalue   Difference    Proportion    Cumulative
                  
          Comp1       9.68133      5.46727    0.1257    0.1257
          Comp2       4.21405      1.38072    0.0547    0.1805
          Comp3       2.83334      .339437    0.0368    0.2173
          Comp4        2.4939       .17655    0.0324    0.2496
          Comp5       2.31735      .193714    0.0301    0.2797
          Comp6       2.12364      .119125    0.0276    0.3073
          Comp7       2.00451      .045688    0.0260    0.3334
          Comp8       1.95882      .134693    0.0254    0.3588
          Comp9       1.82413      .232787    0.0237    0.3825
          Comp10       1.59134     .0354458    0.0207    0.4031
          I look forward to gaining some insight.

          Thanks a lot
          Deepali
          Deepali Godha

          Comment


          • #6
            Sorry, but I still cannot follow what you are doing here.

            Comment


            • #7
              I am trying to get Lorenz curves (for prevalence of IFA consumption for more than 90 days: y=1) to illustrate inequality across the categories of z (0, 1, 2). Earlier, I had created Lorenz curves for institutional deliveries across years as can be seen in the attached figure. I want to understand why my Lorenz curves (at the 100th percentile- the top right corner) spread out as lines and do not meet the line of equality to form a curve (Referring to Figure 2 v191_graph). Figure-Lorenz curves.docx Figure 2 v191_graph.gph

              Thank you
              Deepali
              Deepali Godha

              Comment


              • #8
                I was thinking that maybe this is because the PCA was done for all categories of z in the same dataset rather than creating the wealth index for the categories separately. But if that was so, then I should have been able to get a curve with both ends meeting the line of equality when I opted for a Lorenz curve for the whole dataset (without asking 'glcurve' to split by z). I still get a line.
                Also, I noticed that the y-axis does not show the cumulative 100% of the population. The maximum it shows is up to around 65%. This means that instead of giving the cumulative prevalence of >90 IFA in population, it is just showing the actual prevalence. I don't understand why that is so?
                Deepali Godha

                Comment


                • #9
                  Hello Nick,

                  I was able to locate my error. As you had noted in #4, it was in the command. I used the following command and it worked.
                  Code:
                  glcurve y, pvar(p1) glvar(Lorenz) sortvar(v191) lorenz replace by(z) split saving(new_graph)
                  Many thanks for your advice.

                  Deepali
                  Deepali Godha

                  Comment


                  • #10
                    I do have a further request. Please advise on the Stata command to test dominance. Earlier it was a User-written command-"dominance" but now it is not working.

                    Thank you
                    Deepali
                    Deepali Godha

                    Comment


                    • #11
                      Good to hear of progress in #9 but now please start a new thread.

                      Comment


                      • #12
                        hello, please i want to plot a lorentz concentration curve of commulative % of vaccination status vrs commulative % of accessibility ranked by income quintiles in stata. i am new here and i dont know how to go by it

                        Comment


                        • #13
                          #12

                          To get a Lorenz curve from cumulative percents, much depends on whether you already have the cumulative percents or need to calculate them. There is little point in trying to guess at your data layout so please read https://www.statalist.org/forums/help#stata and show us a real or realistic data example. It can and indeed should be simple, but enough to show what you have precisely.

                          Comment


                          • #14
                            i have two variables namely vaccinationstatus, which is categorical. then i have my income quintiles that i have name quintile. what i want the stata commands to plot a lorenz curve for those two. also the study was conducted in two different district; Tolon and Juaben Districts and i would like to express the lorenz curve in that format too. the two districts are all in one variable called district.

                            Comment

                            Working...
                            X