Announcement

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

  • Box plot axis adjustment

    Hi all,
    I'm currently working on my undergraduate dissertation, titled "The Macroeconomic Determinants of Mental Health". I'm currently trying to produce a box plot of my Inflation variable, to show the reader that there are some very obvious outliers in the data. Below is the code I am using:
    Code:
    graph box Inflation
    However, this produces the following box plot:
    Click image for larger version

Name:	Screenshot 2021-04-10 at 22.43.22.png
Views:	1
Size:	120.9 KB
ID:	1602780


    Is there a way I can adjust the axis so that, say, between -50 and 100 the axis in enlarged, then after 100 the gaps between each number is smaller? I hope I have explained that clearly. I think something like this would allow me to visualise the box plot better. I did have a go doing this through the Graphics tab, but still no luck. If anyone knows how to alter the axis in that way, or alter the blox plot in any way that might make it easier to interpret, your advice would be greatly appreciated.

    Thank you

  • #2
    Code:
    clear
    input str52 country str3 countrycode int year float inflation
    "Arab World" "ARB" 2016 .6089571
    "Caribbean small states" "CSS" 2016 1.3558
    "Central Europe and the Baltics" "CEB" 2016 .9505549
    "Early-demographic dividend" "EAR" 2016 3.6117885
    "East Asia & Pacific" "EAS" 2016 2.1874154
    "East Asia & Pacific (excluding high income)" "EAP" 2016 2.94403
    "East Asia & Pacific (IDA & IBRD countries)" "TEA" 2016 2.94403
    "Euro area" "EMU" 2016 .7908985
    "Europe & Central Asia" "ECS" 2016 1.0888522
    "Europe & Central Asia (excluding high income)" "ECA" 2016 3.8997526
    "Europe & Central Asia (IDA & IBRD countries)" "TEC" 2016 3.6103494
    "European Union" "EUU" 2016 .8720583
    "Fragile and conflict affected situations" "FCS" 2016 4.520237
    "Heavily indebted poor countries (HIPC)" "HPC" 2016 4.973579
    "High income" "HIC" 2016 .7410975
    "IBRD only" "IBD" 2016 2.2976477
    "IDA & IBRD total" "IBT" 2016 3.642463
    "IDA blend" "IDB" 2016 2.14766
    "IDA only" "IDX" 2016 4.520237
    "IDA total" "IDA" 2016 4.4813094
    "Late-demographic dividend" "LTE" 2016 2.01799
    "Latin America & Caribbean" "LCN" 2016 3.656492
    "Latin America & Caribbean (excluding high income)" "LAC" 2016 3.772871
    "Latin America & the Caribbean (IDA & IBRD countries)" "TLA" 2016 3.670521
    "Least developed countries: UN classification" "LDC" 2016 4.973579
    "Low & middle income" "LMY" 2016 3.670521
    "Low income" "LIC" 2016 5.513515
    "Lower middle income" "LMC" 2016 3.670521
    "Middle East & North Africa" "MEA" 2016 .8665991
    "Middle East & North Africa (excluding high income)" "MNA" 2016 1.3046795
    "Middle East & North Africa (IDA & IBRD countries)" "TMN" 2016 1.6018414
    "Middle income" "MIC" 2016 3.5058174
    "North America" "NAC" 2016 .9439842
    "OECD members" "OED" 2016 .8484466
    "Other small states" "OSS" 2016 2.0989094
    "Pacific island small states" "PSS" 2016 4.485258
    "Post-demographic dividend" "PST" 2016 .9505549
    "Pre-demographic dividend" "PRE" 2016 5.078454
    "Small states" "SST" 2016 2.1797202
    "South Asia" "SAS" 2016 3.924549
    "South Asia (IDA & IBRD)" "TSA" 2016 3.924549
    "Sub-Saharan Africa" "SSF" 2016 4.973579
    "Sub-Saharan Africa (excluding high income)" "SSA" 2016 5.116205
    "Sub-Saharan Africa (IDA & IBRD countries)" "TSS" 2016 4.973579
    "Upper middle income" "UMC" 2016 2.2976477
    "World" "WLD" 2016 2.084774
    "Afghanistan" "AFG" 2016 5.123375
    "Albania" "ALB" 2016 -.2117132
    "Algeria" "DZA" 2016 .8899039
    "American Samoa" "ASM" 2016 2.534047
    "Andorra" "AND" 2016 .6912965
    "Angola" "AGO" 2016 27.421314
    "Antigua and Barbuda" "ATG" 2016 1.5554626
    "Argentina" "ARG" 2016 40.67531
    "Armenia" "ARM" 2016 .5173245
    "Australia" "AUS" 2016 -.4137232
    "Austria" "AUT" 2016 1.0888522
    "Azerbaijan" "AZE" 2016 14.611432
    "Bahamas, The" "BHS" 2016 .02828039
    "Bangladesh" "BGD" 2016 6.727836
    "Barbados" "BRB" 2016 -3.1800106
    "Belarus" "BLR" 2016 7.761322
    "Belgium" "BEL" 2016 1.5839033
    "Belize" "BLZ" 2016 .5143789
    "Benin" "BEN" 2016 -.17890827
    "Bhutan" "BTN" 2016 4.2373095
    "Bolivia" "BOL" 2016 -1.746445
    "Bosnia and Herzegovina" "BIH" 2016 1.492236
    "Botswana" "BWA" 2016 11.500506
    "Brazil" "BRA" 2016 8.332567
    "Brunei Darussalam" "BRN" 2016 -9.181009
    "Bulgaria" "BGR" 2016 2.2462254
    "Burkina Faso" "BFA" 2016 6.254055
    "Burundi" "BDI" 2016 3.804735
    "Cabo Verde" "CPV" 2016 -.8710503
    "Cambodia" "KHM" 2016 3.4561174
    "Cameroon" "CMR" 2016 .03042866
    "Canada" "CAN" 2016 .6121684
    "Central African Republic" "CAF" 2016 6.35505
    "Chad" "TCD" 2016 -4.942626
    "Chile" "CHL" 2016 3.766417
    "China" "CHN" 2016 1.2217997
    "Colombia" "COL" 2016 5.852432
    "Comoros" "COM" 2016 6.943819
    "Congo, Dem. Rep." "COD" 2016 5.513515
    "Congo, Rep." "COG" 2016 -6.427616
    "Costa Rica" "CRI" 2016 2.2976477
    "Cote d'Ivoire" "CIV" 2016 1.568028
    "Croatia" "HRV" 2016 -.10451487
    "Cyprus" "CYP" 2016 -.8615239
    "Czech Republic" "CZE" 2016 1.235923
    "Denmark" "DNK" 2016 -.04644416
    "Dominica" "DMA" 2016 5.875658
    "Dominican Republic" "DOM" 2016 .8068772
    "Ecuador" "ECU" 2016 .9094727
    "Egypt, Arab Rep." "EGY" 2016 6.252383
    "El Salvador" "SLV" 2016 .4822559
    "Equatorial Guinea" "GNQ" 2016 -6.678226
    "Estonia" "EST" 2016 1.5926924
    "Ethiopia" "ETH" 2016 9.450111
    "Fiji" "FJI" 2016 6.564051
    "Finland" "FIN" 2016 .7908985
    "France" "FRA" 2016 .38526565
    "Gabon" "GAB" 2016 -2.2872767
    "Gambia, The" "GMB" 2016 7.140481
    "Georgia" "GEO" 2016 4.1891556
    "Germany" "DEU" 2016 1.3292108
    "Ghana" "GHA" 2016 17.424591
    "Greece" "GRC" 2016 -.9563052
    "Grenada" "GRD" 2016 2.1720252
    "Guam" "GUM" 2016 1.3331106
    "Guatemala" "GTM" 2016 3.87522
    "Guinea" "GIN" 2016 8.528125
    "Guinea-Bissau" "GNB" 2016 6.591823
    "Guyana" "GUY" 2016 5.987973
    "Haiti" "HTI" 2016 12.706845
    "Honduras" "HND" 2016 3.670521
    "Hong Kong SAR, China" "HKG" 2016 1.7773646
    "Hungary" "HUN" 2016 .9592844
    "Iceland" "ISL" 2016 2.1130447
    "India" "IND" 2016 3.6117885
    "Indonesia" "IDN" 2016 2.450128
    "Iran, Islamic Rep." "IRN" 2016 1.6071895
    "Iraq" "IRQ" 2016 -12.91721
    "Ireland" "IRL" 2016 .02073244
    "Israel" "ISR" 2016 .8432943
    "Italy" "ITA" 2016 .8484466
    "Jamaica" "JAM" 2016 4.5953856
    "Japan" "JPN" 2016 .27355775
    "Jordan" "JOR" 2016 1.0075176
    "Kazakhstan" "KAZ" 2016 13.638433
    "Kenya" "KEN" 2016 8.026257
    "Kiribati" "KIR" 2016 7.251715
    "Korea, Rep." "KOR" 2016 1.8073034
    "Kosovo" "XKX" 2016 -.33042485
    "Kuwait" "KWT" 2016 -6.133644
    "Kyrgyz Republic" "KGZ" 2016 2.4756916
    "Lao PDR" "LAO" 2016 3.022521
    "Latvia" "LVA" 2016 .27402365
    "Lebanon" "LBN" 2016 -1.684206
    "Lesotho" "LSO" 2016 2.949559
    "Liberia" "LBR" 2016 4.973579
    "Lithuania" "LTU" 2016 .9505549
    "Luxembourg" "LUX" 2016 -1.309389
    "Macao SAR, China" "MAC" 2016 .8850223
    "Macedonia, FYR" "MKD" 2016 6.259109
    "Madagascar" "MDG" 2016 6.680803
    "Malawi" "MWI" 2016 19.54413
    "Malaysia" "MYS" 2016 1.9512063
    "Maldives" "MDV" 2016 -.6741138
    "Mali" "MLI" 2016 1.5303653
    "Malta" "MLT" 2016 1.6045482
    "Marshall Islands" "MHL" 2016 6.206966
    "Mauritania" "MRT" 2016 4.1
    "Mauritius" "MUS" 2016 2.084774
    "Mexico" "MEX" 2016 4.6095824
    "Micronesia, Fed. Sts." "FSM" 2016 4.735831
    "Moldova" "MDA" 2016 5.398558
    "Mongolia" "MNG" 2016 2.1232946
    "Montenegro" "MNE" 2016 5.101006
    "Morocco" "MAR" 2016 1.6018414
    "Mozambique" "MOZ" 2016 12.166992
    "Myanmar" "MMR" 2016 3.5555174
    "Namibia" "NAM" 2016 7.906137
    "Nauru" "NRU" 2016 5.69526
    "Nepal" "NPL" 2016 5.071743
    "Netherlands" "NLD" 2016 .5840578
    "New Zealand" "NZL" 2016 2.4172025
    "Nicaragua" "NIC" 2016 4.0847936
    "Niger" "NER" 2016 -.4354734
    "Nigeria" "NGA" 2016 9.54367
    "Northern Mariana Islands" "MNP" 2016 3.509096
    "Norway" "NOR" 2016 -1.1140699
    "Pakistan" "PAK" 2016 .545966
    "Palau" "PLW" 2016 2.257207
    "Panama" "PAN" 2016 .9333116
    "Papua New Guinea" "PNG" 2016 6.073164
    "Paraguay" "PRY" 2016 5.279241
    "Peru" "PER" 2016 3.642463
    "Philippines" "PHL" 2016 1.6587112
    "Poland" "POL" 2016 .4162496
    "Portugal" "PRT" 2016 1.5176493
    "Puerto Rico" "PRI" 2016 4.558288
    "Qatar" "QAT" 2016 -9.417459
    "Romania" "ROU" 2016 2.1611521
    "Russian Federation" "RUS" 2016 3.6103494
    "Rwanda" "RWA" 2016 4.892834
    "Samoa" "WSM" 2016 -1.5754114
    "San Marino" "SMR" 2016 .6529495
    "Sao Tome and Principe" "STP" 2016 4.4773607
    "Saudi Arabia" "SAU" 2016 -2.513845
    "Senegal" "SEN" 2016 1.1135055
    "Serbia" "SRB" 2016 2.534555
    "Seychelles" "SYC" 2016 -4.981936
    "Sierra Leone" "SLE" 2016 5.861245
    "Singapore" "SGP" 2016 -1.434629
    "Slovak Republic" "SVK" 2016 -.4484121
    "Slovenia" "SVN" 2016 .8956701
    "Solomon Islands" "SLB" 2016 4.485258
    "South Africa" "ZAF" 2016 7.011293
    "Spain" "ESP" 2016 .2833042
    "Sri Lanka" "LKA" 2016 3.5659184
    "St. Kitts and Nevis" "KNA" 2016 1.3558
    "St. Lucia" "LCA" 2016 .1578381
    "St. Vincent and the Grenadines" "VCT" 2016 -.13161644
    "Sudan" "SDN" 2016 -2.745336
    "Suriname" "SUR" 2016 30.537893
    "Swaziland" "SWZ" 2016 5.25883
    "Sweden" "SWE" 2016 1.5932513
    "Switzerland" "CHE" 2016 -.5661435
    "Tajikistan" "TJK" 2016 5.27584
    "Tanzania" "TZA" 2016 6.735785
    "Thailand" "THA" 2016 1.777944
    "Timor-Leste" "TLS" 2016 5.033534
    "Togo" "TGO" 2016 2.742931
    "Tonga" "TON" 2016 1.692738
    "Trinidad and Tobago" "TTO" 2016 -.6318471
    "Tunisia" "TUN" 2016 5.492198
    "Turkey" "TUR" 2016 8.098262
    "Turkmenistan" "TKM" 2016 -4.83787
    "Tuvalu" "TUV" 2016 2.94403
    "Uganda" "UGA" 2016 3.525151
    "Ukraine" "UKR" 2016 17.142395
    "United Arab Emirates" "ARE" 2016 -5.443039
    "United Kingdom" "GBR" 2016 1.9743427
    "United States" "USA" 2016 1.2758
    "Uruguay" "URY" 2016 7.048512
    "Uzbekistan" "UZB" 2016 7.621512
    "Vanuatu" "VUT" 2016 2.1874154
    "Vietnam" "VNM" 2016 1.1106492
    "West Bank and Gaza" "PSE" 2016 1.534893
    "Yemen, Rep." "YEM" 2016 4.555216
    "Zambia" "ZMB" 2016 14.328273
    "Zimbabwe" "ZWE" 2016 1.3099773
    end
    Regarding this goal:
    to show the reader that there are some very obvious outliers in the data
    I do think that the graph is doing this job rather perfectly.

    Anyhow, there are many ways to see more details in the compressed part of the data. I'd just list two that came to mind:

    1) Use subplot to show the total boxplot and then a boxplot with those big numbers removed. Afterwards, use -graph combine- to group them into one graph:

    Code:
    graph box inflation, saving(g01, replace)
    graph box inflation if inrange(inflation,-13,13), saving(g02, replace)
    graph combine g01.gph g02.gph
    Click image for larger version

Name:	image_22024.png
Views:	1
Size:	25.2 KB
ID:	1602786


    2) Use scale break. A great reference is on pg.338 at https://journals.sagepub.com/doi/pdf...867X1201200210. This however would not work well with boxplot. Instead, I created a rank variable of the country's inflation, and plot the actual inflation against that. The cool feature is that we can use different scales. Here for the lower group, the inflation is identical, and for the high group, the inflation scale is log:

    Code:
    egen inflation_rank = rank(inflation)
    * Original scale:
    twoway scatter inflation inflation_rank, msize(tiny)
    * With scale break
    twoway scatter inflation inflation_rank if inflation <= 13, ///
    xscale(r(1,234)) ytitle(inflation) saving(p01, replace)
    twoway scatter inflation inflation_rank if inflation >  13, ///
    xscale(r(1,234) off) yscale(log) ytitle(ln(inflation)) xtitle("") saving(p02, replace)
    graph combine "p02" "p01", imargin(small) row(2)
    Click image for larger version

Name:	image_22025.png
Views:	1
Size:	41.8 KB
ID:	1602787

    If you're worried that having log and original scale together maybe confusing, I'd strongly suggest check out the pg.338 example of the article above. In that example, the scales are the same, but the spacing of the scales were changed from in 1,000 years to 250 years. Which could help compress a very wide scale with large numbers.
    Last edited by Ken Chui; 10 Apr 2021, 17:35.

    Comment


    • #3
      This is a bit beyond the scope of your question, but in cases like this I would just show a second boxplot without the outliers. The scale break is an interesting idea but I would think you could confuse the reader that way.

      Comment


      • #4
        Thanks Jonathan Horowitz. I added one comment at the end addressing this concern. This can be circumvent by keeping the same scale, but enlarging the magnitude of the ticks on the axis.

        Comment


        • #5
          There is no perfect solution here.

          A difficulty with the first solution in #2 is that median, IQR and thus the thresholds lower quartile - 1.5 IQR and upper quartile + 1.5 IQR are not preserved when you take a subset. That is fixable. My suggestion here, however, is that the box plot faff of drawing whiskers as a way to select points to show individually does not help and is better avoided. With perhaps 200 countries as in #2 there is enough space to show all the data.

          My own preference would be to use one of

          cube roots

          neglog = sign() * log(1 + abs())

          asinh()

          which all have the merit of pulling in outliers and of working cleanly with values that can be positive, zero, or negative. On cube roots see https://www.stata-journal.com/articl...article=st0223

          I am the author of the paper discussing scale breaks cited in #2. On the whole I don't like them and don't see that they are the best solution here.

          Here is some code for Ken's data from #2. stripplot and mylabels are both from SSC.

          Code:
          set scheme s1color 
          stripplot inflation, cumul box vertical center yla(, ang(h)) name(G1, replace)
          gen curtinf = sign(inflation)*abs(inflation)^(1/3)
          mylabels -10(10)40, myscale(sign(@)*abs(@)^(1/3)) local(yla)
          label var curtinf "inflation (cube root scale)"
          stripplot curtinf, cumul box vertical center yli(0, lc(gs12) lw(vthin)) yla(`yla', ang(h)) name(G2, replace)
          graph combine G1 G2
          Click image for larger version

Name:	inflation.png
Views:	1
Size:	34.7 KB
ID:	1602796

          This is a quantile-box plot. The median and quartiles are plotted against the vertical magnitude scale -- you got that -- but also probabilities 0.25 0.5 0;75 are plotted against horizontal probability scale; So half the data points are inside the box -- and half outside.

          The gap around zero on cube root scale is not a bug. The cube root transformation is steepest at (zero, zero). In principle values near or very near zero could be reported but they just are not present in this dataset. The side-effect is to segregate countries suffering inflation (strict sense) from those suffering deflation.

          With Ken's dataset the outliers are tamed, but I am confident that Yasmin's outliers will still be visible as such. By eye her (minimum, second largest, largest) are around (0, 8000, 24000) so their cube roots are around (0, 20, 29) and the very largest will still be utterly distinct.

          Comment


          • #6
            Thanks for the input, Nick Cox. Learned a lot.

            Comment


            • #7
              Hi, thank you all for your help. As suggested in #5, I used the code:
              Code:
              ssc install stripplot
              set scheme s1color 
              stripplot Inflation, cumul box vertical center yla(, ang(h)) name(G1, replace)
              gen curtinf = sign(Inflation)*abs(Inflation)^(1/3)
              mylabels -10(10)40, myscale(sign(@)*abs(@)^(1/3)) local(yla)
              label var curtinf "Inflation (cube root scale)"
              stripplot curtinf, cumul box vertical center yli(0, lc(gs12) lw(vthin)) yla(`yla', ang(h)) name(G2, replace)
              graph combine G1 G2
              This gave me the following graph:
              Click image for larger version

Name:	Screenshot 2021-04-11 at 12.00.17.png
Views:	1
Size:	112.8 KB
ID:	1602836
              As you can see, the graph is still unclear. Am I going wrong somewhere?

              Thanks

              Comment


              • #8
                Code:
                 
                 mylabels -10(10)40, myscale(sign(@)*abs(@)^(1/3)) local(yla)
                is customised to Ken Chui's data from #2 as labels to show. You will want your labels to go up to 25000, not just 40. What other labels work well is harder to say without a first stab at a plot.

                What you are showing is the graph named G1 in the code. The box may well be buried by the data points.

                I can't see graph G2 here nor can I work out why it doesn't appear. Can you please post the data? Use the output of

                Code:
                dataex Inflation, count(500)
                where 500 is expected to be big enough to ensure that you post all values.

                Comment


                • #9
                  Hi Nick,
                  Below is the output of
                  Code:
                  dataex Inflation, count(500)
                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input double Inflation
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                   12.6862687216715
                   6.78459655001657
                   8.68057078513406
                   26.4186641547444
                  -6.81116108898995
                    2.1785375238942
                   11.8041858089129
                   6.44121280934118
                   7.38577178397857
                   4.67399603536339
                  -.661709164713696
                   4.38389195513914
                    4.9759515055383
                   .626149149168811
                   2.30237251516844
                                  .
                                  .
                   226.005421253526
                   85.0047512387157
                   22.5650526933696
                   7.79321853789214
                   12.7254778087103
                   33.1802743753956
                   20.6428588670597
                   .389437653561604
                  .0500181363468265
                   3.10758827031434
                    7.7705258343155
                   .484002611818489
                   2.28001916938101
                   2.36658195679796
                   2.37072831904283
                   2.93268248162319
                   3.36313757366391
                   2.23139683475867
                   3.62233541062328
                   3.42912324722163
                   2.03159593996543
                   1.93761754903872
                   1.62586504402605
                   1.89617402592348
                   1.27543168367409
                   1.98666133171194
                   2.02805963071135
                   1.41109078954244
                   16.6525343885433
                   25.8863869348513
                   31.6696619117149
                   20.5403261235826
                   29.0476561173071
                   29.7796264864999
                    18.679075860175
                   5.73352275357186
                   4.95016163793115
                   2.64551113392798
                   .339163189071755
                   4.22598834854679
                   1.41830192345045
                     4.268953958395
                   3.96180030257191
                   1.38244656662119
                   2.31149918514421
                   3.67899574741703
                   4.85859062814938
                   5.73706036145632
                   3.91106195534027
                   4.52421150505276
                   8.89145091062314
                   3.25423910998847
                   2.91692692067457
                   4.78444700693894
                   6.39769480268749
                   5.59111590961673
                   4.26999020467078
                   1.95176821052894
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                   1.12128789571148
                   .771779796900182
                   1.40279663573984
                   2.40765801293492
                   1.99353055152456
                   2.03007757853236
                   2.09875196709306
                   1.78778537419119
                    1.4160525940974
                   5.33380639820237
                  -.550159995508912
                    3.3700254022015
                   3.45674967234602
                   3.37688044338876
                   1.05949782356168
                    1.0894415743536
                   .968993458825599
                  -.489437796230513
                   2.43248789041366
                   1.20715793367003
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                                  .
                   3373.75944336293
                   175.951325534583
                    18.681185640036
                    13.960764121791
                    8.6724863238516
                   .648245760470397
                  -.790883768934766
                   3.14590464685019
                   1.06004929341667
                   4.72155336605342
                   6.96126135875792
                   .638928002410126
                   2.89235662459002
                   4.40736089644519
                   8.94995335353386
                   3.40676682683799
                   8.17636138473956
                    7.6500080785929
                   2.55802007757907
                   5.78966778544654
                   2.98130868933673
                   3.73169119261695
                  -1.40360755900906
                   .969553268816231
                   2.52023382001631
                   1.44344660770702
                   7.33302195235869
                   3.17667536988686
                   1.01223112610711
                   1.75365344467641
                   1.96963479688142
                   4.62776659959758
                   2.61538461538462
                   .224887556221881
                   .860134629768157
                   1.48312940304038
                   4.45743514797225
                    4.4071353620147
                   2.98157453936349
                   2.73259596616783
                   2.34325522482587
                   2.69183168316831
                   3.55528773727028
                   2.32761128891476
                   4.35029854990047
                   1.77111716621252
                   2.91834002677376
                   3.30385015608744
                   1.76278015613193
                   2.44988864142539
                   2.48792270531403
                   1.50836672165921
                   1.27699094497328
                   1.94864740944522
                   1.91140094445692
                   1.61076787290379
                   3.26187312306823
                   3.33742884548212
                   4.02084559057212
                   3.63178559452543
                   2.95340390976125
                   2.24336668054029
                   1.86097376901842
                   1.30598307237497
                   .922465840847906
                   .568990766899814
                   2.34486455542566
                   2.64999922285055
                   1.81035953871319
                   1.35555673319826
                   2.06120354001778
                   2.29913882222146
                   1.44154696188379
                   2.16855599824037
                   3.21595022953491
                   .506308350120954
                   1.81353628033681
                   3.28658197365512
                   2.48567352860068
                   2.00015891157196
                   1.60580414549751
                   .896565315628228
                   .891592367302732
                   2.08126858275521
                   1.99838187702266
                   1.53089553422702
                                  .
                                  .
                  -10.6300971576201
                   1128.00002429404
                   1662.21594875899
                   411.759641777268
                   19.7948028061898
                    3.6743480968473
                    -.7726978860332
                   -8.5251700053606
                   1.80500303704356
                   1.54719590152278
                    2.7711647199827
                   2.23386492967051
                   6.70893042797785
                    9.6795073191705
                   8.32892482863211
                   16.6612577660859
                   20.8372928966452
                    1.4631599735878
                   5.73238742950904
                    7.8523837676544
                   1.06810301380606
                   2.41886988429669
                   1.38972635776452
                   4.00943826686826
                   12.4494955236962
                   12.9399841146895
                   2.26351685730081
                   2.60833956534685
                   4.66931912018676
                   7.11468120203626
                   5.73819886173449
                   2.72289766970589
                   1.39933423745549
                   2.06699495410041
                   1.37913741223667
                   .544150383378706
                   1.33661336613368
                   1.25424826023631
                    1.6063294174058
                   2.04498977505121
                   2.17357792508091
                   3.02504526252236
                   .981914036757665
                   1.59160618079803
                   2.38982627439253
                   2.49257794939399
                   4.48955995375059
                    2.0627347345268
                   1.34402738392836
                   3.19878141660321
                   1.97336755976255
                   1.03467035109885
                    47.775962542527
                  -30.2431602281729
                  -.330038395555927
                   1.49992623313609
                   2.26751510061695
                   2.49123527368055
                   .929335437489111
                   .764419735927607
                  -.172413793103325
                   2.53886010362696
                   .816910897759777
                   2.70403475064702
                  -.452227382530316
                   2.43155133955926
                  -.366533864541796
                   -1.2875879718491
                  -.704852953090751
                  -1.20757180156661
                  -.495540138751155
                   1.59362549800784
                   2.35294117647063
                   2.58620689655173
                   2.00746965452849
                   3.25666666666702
                   3.52600316363722
                   2.79551283550411
                   1.96188468334624
                  -.401486988847566
                   2.75828605553897
                   3.30100613853474
                   2.64629146477823
                   1.83951987503599
                   2.80059469750482
                    1.3873437602251
                   2.08481249596594
                                  .
                   6.12671846981463
                   6.35736412278233
                   3.63407691798491
                   3.01481859989799
                     5.313740079365
                   10.2978117947205
                   2.37712902953225
                   5.30560105668804
                    8.4022379561323
                   6.10669589841957
                   2.20825620937534
                   2.00717374213842
                   3.33256493271908
                   5.66870773441478
                   7.58753638504692
                   7.04661816222037
                   6.76526117054756
                   9.10698496905385
                   8.90194489465155
                   5.42347236174678
                   8.12667639169919
                   11.3951651552399
                   6.21750422069283
                   7.53040640913171
                   6.99163889220854
                   6.19428022984988
                    5.5135257269299
                   5.70207015717245
                    5.5436213948647
                   5.59199639930633
                   3.07457271078019
                    6.2575266327002
                   6.09389302994641
                   1.11343933604483
                  .0772043884602162
                   1.87886279357232
                   2.38615222842323
                   7.71053878969884
                  -1.26888660701212
                   1.56006240249606
                   2.43581303489138
                   2.57783490431289
                   .125249458055994
                   1.61943319838056
                   1.39442231075689
                   6.08218729535043
                   7.30766262828941
                   4.03422982885069
                    8.1081081081078
                   3.64386189258338
                   5.82421853311865
                   9.43220240177216
                   4.53334753888771
                   1.81410436049101
                   1.76950322089726
                  -1.11278992510961
                   1.28192813061894
                   4.66018463955997
                   3.67381410406798
                   4.10028964518463
                                  .
                                  .
                                  .
                   1190.22923349187
                   2221.01656992039
                   709.346032118606
                   52.7120767531954
                   63.9373663357479
                   72.8697170535353
                   293.678750889773
                   168.620235850933
                   61.1349331618477
                   42.5375481348794
                   28.3978399133474
                   18.1082424937646
                   10.3388794457933
                   6.99712903535585
                   8.42675273505308
                   14.8378764828254
                   12.9456563410401
                  end
                  I must say, though, that for Inflation I have 7325 observations. I would post the output for:
                  Code:
                  dataex Inflation, count(7325)
                  However because the number of observations is so large, Stata doesn't display them all.

                  Thanks
                  Last edited by Yasmin Pewsey; 11 Apr 2021, 05:53.

                  Comment


                  • #10
                    This is the graph of G2. I'n not sure why it is not combining with G1.
                    Click image for larger version

Name:	Screenshot 2021-04-11 at 12.44.48.png
Views:	0
Size:	0
ID:	1602853
                    Thanks

                    Comment


                    • #11
                      I just realised my graph may have not attached properly. This is the graph G2:
                      Click image for larger version

Name:	Screenshot 2021-04-11 at 12.57.15.png
Views:	1
Size:	101.1 KB
ID:	1602855

                      Comment


                      • #12
                        I though this might be of help:

                        When I use
                        Code:
                        su Inflation, d
                        It gives me the output:
                        Click image for larger version

Name:	Screenshot 2021-04-11 at 13.09.52.png
Views:	1
Size:	102.8 KB
ID:	1602860

                        As a side note, what is the difference between the values under the heading "Percentiles" and the values under the heading "Smallest" and "Largest"?
                        Last edited by Yasmin Pewsey; 11 Apr 2021, 06:15.

                        Comment


                        • #13
                          OK, so you have panel data which wasn't clear to me (not that you were trying to hide it).

                          To summarize my impressions:

                          1. Plotting all the data on the raw scale (see the graph in #7) shows up the skewness and outliers very well and may well do what you want to do. Something like
                          quantile would work directly too. Given so many data points I would switch to ms(oh). I suggest that a basic box plot doesn't work nearly so well.

                          2. If you want to see more by pulling in outliers, you need a scale that honours the negative, zero and positive values alike so plain logarithms just won't cope. You need something exotic as a scale which carries a burden of understanding it yourself and of explaining it to your markers. I was last author of a paper in Nature which included a cube root scale and the initial reaction of reviewers was a restrained version of "Whaattt is this about?".

                          3.
                          The summarize output allows some play with different scales.

                          This code is just play so that you can see some of the choices.

                          Code:
                          * Example generated by -dataex-. For more info, type help dataex
                          clear
                          input float tryit
                            -30
                            -18
                            -16
                            -12
                              4
                           4129
                           4734
                           7842
                          23773
                          end
                          
                          gen curt = sign(tryit) * abs(tryit)^(1/3)
                          
                          mylabels -50 0 50 1000 5000 (5000) 25000, myscale(sign(@)*abs(@)^(1/3)) local(yla)
                          
                          scatter curt tryit , yla(`yla', ang(h)) name(T1)
                          
                          gen neglog = sign(tryit) * log1p(abs(tryit))
                          
                          mylabels -20 0 20 100 500 2500 12500, myscale(sign(@)*log1p(abs@)) local(yla)
                          
                          scatter neglog tryit, yla(`yla', ang(h)) name(T2)
                          You must run the code all at once; otherwise the local definitions won't be visible to the commands that use them.

                          Comment

                          Working...
                          X