Announcement

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

  • Bar graph?

    Dear All, I have the following data
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(lly btot privo) int rgdpsh
     18.3381  74.1596 15.68565 4462
     51.7266  92.6655 54.81786 7782
     67.4966  98.4359 65.29842 5143
     24.6914  86.3752 13.54584  952
     51.5927  91.8502 40.64384 2666
     49.0197  92.0092 25.64779 5495
     16.3877  31.5974 13.14186 1148
     19.1631  61.6758 21.44617 1784
    56.50429   88.997 60.86423 7258
     22.9597  52.8085  27.8104 2885
     22.4096  80.1646 22.08222 1684
     29.3846  72.8176 21.77378 2096
     74.4912    92.72 62.01511 2037
     49.4787  88.0999 42.44699 6760
     20.5826  73.3352 19.11292 1195
     20.0486  62.1616 17.98507 1461
     26.9358  72.0441 22.84953 1427
     37.4766  96.9463  23.6507 2108
      45.349  97.2227 51.78182 5291
       63.37  96.5411 75.46823 5823
    57.46272   97.571 76.45579 6570
      17.577  39.7841  5.07367  894
     53.3381  74.3563 36.72324 2093
     20.2198  75.1588 13.31726 1660
     52.9648   58.018  20.5166 1596
     22.6035  23.7174   7.7135  924
     23.0376  76.5371  23.8559 1039
     31.7611  88.9397 34.79329 4964
     32.9494  63.6846 19.53084  766
     54.7421  94.7271 49.14149 3311
     51.9463  84.2815 37.43197 3477
    77.47569  87.7728 59.08989 4564
     36.8505  78.0906 24.54591 1773
    125.9392  96.7181 128.3783 2954
     35.7355  81.2692 22.78104  659
     41.0236  83.9456  65.4788  904
      9.7347  37.9002 10.16035  717
     63.7392  96.4534 46.89995 1420
    143.4259   92.565 43.97008 1374
     46.8707  82.2124 24.36066 2862
     25.5744  69.3824 22.89418 2836
     20.2658  57.8637  7.72334  628
    71.41078  98.0962 86.69409 6077
      49.626    82.43 37.59236 7960
     14.4336  83.8875 13.05017  532
     54.0413  90.0224 81.62302 5610
     38.6757  67.8879 20.76761  638
     33.3723   71.971 40.22082 1575
     31.0542   89.117  20.8444 1235
     17.6203  65.2917 14.51989 1177
     18.5189  86.0365 13.32469 2019
     27.5044  81.4047 26.97613 1133
      78.022  90.3459 55.01267 1869
     22.7968   84.538 27.50557 1047
     16.8288  49.5504  5.06637  878
     51.4366  94.7736 71.93586 2191
     70.3053  92.7402 65.04914 3123
     30.3415  57.7968 16.20979 1259
     53.4937  88.9401 89.11234 7592
    123.4055  98.9879 141.2944 9409
     43.3227  46.9346   8.8252 1575
     66.9684  95.7224 57.85528 1256
     47.7859  84.6563 47.27738  943
        32.9  82.0514 21.88465  367
     37.4615  91.7183 31.39167 5627
     48.6267  83.5528 46.31212 6823
     62.1195  93.1142 113.0658 9895
     29.4668  59.2383 21.21116 3968
     36.8425  90.8998 33.12155 6338
     16.0277  28.5825  4.08484  489
    46.92189 75.80044 23.03637  989
    end
    where the financial development indicators are
    1. lly: LIQUID LIABILITIES
    2. btot: COMMERCIAL-CENTRAL BANK
    3. privo: PRIVATE CREDIT
    I use the following code to generate four income groups (where `rgdpsh' is the income per capita):
    Code:
    xtile rgdpsh4= rgdpsh, nq(4)
    and I'd like to have a figure like the following:
    Click image for larger version

Name:	llb00jme-cs-f1.png
Views:	1
Size:	36.2 KB
ID:	1455573

    Any suggestion is highly appreciated!
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Dear River,
    The following code or similar may give you the graph you want ( I have not labelled the variables)
    I have used the mean which gives very similar graph to the one you have posted



    HTML Code:
    xtile rgdpsh4= rgdpsh, nq(4)
    *then
    rangestat (mean) lly btot privo, interval(rgdpsh4, 0, 0)
    collapse (max) btot_mean privo_mean lly_mean, by( rgdpsh4)
    xpose, clear varname
    drop in 1
    gr bar v*, over(_varname)
    Apologies, I am sure there may be more eloquent ways of doing it than my clunky suggestion
    Kind regards
    RS
    Last edited by ram singh; 29 Jul 2018, 03:52.

    Comment


    • #3
      You don't say what you want the graph to show: means? totals? something else?

      Regardless, statplot (SSC) can help. See e.g.

      https://www.stata.com/statalist/arch.../msg00447.html

      http://researchnotes.eric-a-booth.co...-examples.html

      http://researchnotes.eric-a-booth.co...es-part-2.html

      Notes:

      1. VARIABLE LABELS LIKE THIS are surely dysfunctional. They are harder to read, take up more space and for many create a synesthetic sense of SHOUTING.

      2. You don't need a legend when the different quartile bins can be labelled directly.

      3. You don't need different shadings (especially those with irrational mixes of colour) for the same reason.

      4. I'd add units of measurement if I knew what they were.

      5. Text explaining the binning is up to you. In practice it often goes better in the Figure caption.

      Code:
      clear
      input float(lly btot privo) int rgdpsh
       18.3381  74.1596 15.68565 4462
       51.7266  92.6655 54.81786 7782
       67.4966  98.4359 65.29842 5143
       24.6914  86.3752 13.54584  952
       51.5927  91.8502 40.64384 2666
       49.0197  92.0092 25.64779 5495
       16.3877  31.5974 13.14186 1148
       19.1631  61.6758 21.44617 1784
      56.50429   88.997 60.86423 7258
       22.9597  52.8085  27.8104 2885
       22.4096  80.1646 22.08222 1684
       29.3846  72.8176 21.77378 2096
       74.4912    92.72 62.01511 2037
       49.4787  88.0999 42.44699 6760
       20.5826  73.3352 19.11292 1195
       20.0486  62.1616 17.98507 1461
       26.9358  72.0441 22.84953 1427
       37.4766  96.9463  23.6507 2108
        45.349  97.2227 51.78182 5291
         63.37  96.5411 75.46823 5823
      57.46272   97.571 76.45579 6570
        17.577  39.7841  5.07367  894
       53.3381  74.3563 36.72324 2093
       20.2198  75.1588 13.31726 1660
       52.9648   58.018  20.5166 1596
       22.6035  23.7174   7.7135  924
       23.0376  76.5371  23.8559 1039
       31.7611  88.9397 34.79329 4964
       32.9494  63.6846 19.53084  766
       54.7421  94.7271 49.14149 3311
       51.9463  84.2815 37.43197 3477
      77.47569  87.7728 59.08989 4564
       36.8505  78.0906 24.54591 1773
      125.9392  96.7181 128.3783 2954
       35.7355  81.2692 22.78104  659
       41.0236  83.9456  65.4788  904
        9.7347  37.9002 10.16035  717
       63.7392  96.4534 46.89995 1420
      143.4259   92.565 43.97008 1374
       46.8707  82.2124 24.36066 2862
       25.5744  69.3824 22.89418 2836
       20.2658  57.8637  7.72334  628
      71.41078  98.0962 86.69409 6077
        49.626    82.43 37.59236 7960
       14.4336  83.8875 13.05017  532
       54.0413  90.0224 81.62302 5610
       38.6757  67.8879 20.76761  638
       33.3723   71.971 40.22082 1575
       31.0542   89.117  20.8444 1235
       17.6203  65.2917 14.51989 1177
       18.5189  86.0365 13.32469 2019
       27.5044  81.4047 26.97613 1133
        78.022  90.3459 55.01267 1869
       22.7968   84.538 27.50557 1047
       16.8288  49.5504  5.06637  878
       51.4366  94.7736 71.93586 2191
       70.3053  92.7402 65.04914 3123
       30.3415  57.7968 16.20979 1259
       53.4937  88.9401 89.11234 7592
      123.4055  98.9879 141.2944 9409
       43.3227  46.9346   8.8252 1575
       66.9684  95.7224 57.85528 1256
       47.7859  84.6563 47.27738  943
          32.9  82.0514 21.88465  367
       37.4615  91.7183 31.39167 5627
       48.6267  83.5528 46.31212 6823
       62.1195  93.1142 113.0658 9895
       29.4668  59.2383 21.21116 3968
       36.8425  90.8998 33.12155 6338
       16.0277  28.5825  4.08484  489
      46.92189 75.80044 23.03637  989
      end
      label var lly "Liquid liabilities"
      label var btot "Commercial-central bank" 
      label var privo "Private credit" 
      xtile rgdpsh4= rgdpsh, nq(4)
      set scheme s1color 
      statplot lly btot privo, over(rgdpsh4) recast(bar) bar(1, bfcolor(green*0.2)) yla(, ang(h))
      Click image for larger version

Name:	huang2.png
Views:	1
Size:	25.9 KB
ID:	1455577

      Comment


      • #4
        ram singh

        I like rangestat (SSC, as you are asked to explain) too, but

        Code:
        rangestat (mean) lly btot privo, interval(rgdpsh4, 0, 0)
        collapse (max) btot_mean privo_mean lly_mean, by( rgdpsh4)
        itself can be collapsed to

        Code:
        collapse (mean) lly btot privo, by(rgdpsh4)
        You will have now seen in #3 a way to do it without disturbing the dataset shape or layout.

        Comment


        • #5
          Dear Nick,
          Brilliant and thanks for your input. Great to learn from you as always.
          Kind regards,
          RS

          Comment


          • #6
            Dear Ram, Many thanks for the suggestion.
            Ho-Chuan (River) Huang
            Stata 17.0, MP(4)

            Comment


            • #7
              Dear Nick, Sorry not indicating that the `mean' is what I had in mind, and many thanks for the wonderful solutions.
              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment


              • #8
                Dear Nick, As I posted in #1 (Figure 1), the (4) colors in each financial indicator (Liquid liabilities, Commercial-central bank, and Private credit) denotes the mean/average of the indicator of the low, lower middle, upper middle, and high-income countries. As such, any suggestions to make them `colorful'? Thanks.
                Ho-Chuan (River) Huang
                Stata 17.0, MP(4)

                Comment


                • #9
                  As signalled in #3 I can't see any need for, or gain in, adding colours. If your readership doesn't understand 1 2 3 4, then how will colours help? If the 4 bars were for years 2010 2011 2012 2013 would you want different colours? Why add a legend when you don't need one?

                  Less (clutter and arbitrary detail) is more (intelligent), in my view.

                  But statplot is (here) just a wrapper for graph bar, as the help indicates, so asyvars opens up the command to fruit salad and Joseph's technicolour dreamcoat.

                  Comment


                  • #10
                    Dear Nick, After looking at the graph, I think you were right. Thanks.
                    Ho-Chuan (River) Huang
                    Stata 17.0, MP(4)

                    Comment

                    Working...
                    X