Announcement

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

  • bar with confidence interval?

    Dear All, I find this question here (http://bbs.pinggu.org/thread-6292609-1-1.html). How to draw a graph like this. (Unfortunately, no data set is available.)


    Click image for larger version

Name:	bar-with-ci.png
Views:	1
Size:	24.9 KB
ID:	1436095

    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Code:
    twoway bar ... || rcap ...
    Better to show more data on the plot (and if values should always be positive calculate confidence intervals on a more appropriate scale).

    Search phrases: dynamite plots, detonator plots, plunger plots

    http://biostat.mc.vanderbilt.edu/wik...de/Poster3.pdf is worth reading, even though the author's main target is a step beyond what you're showing.
    Last edited by Nick Cox; 25 Mar 2018, 03:34.

    Comment


    • #3
      Dear Nick, I guess I need more assistance. Suppose that I have the data as (webuse grunfeld, clear)
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(company year invest)
      1 1935  317.6
      1 1936  391.8
      1 1937  410.6
      1 1938  257.7
      1 1939  330.8
      1 1940  461.2
      1 1941    512
      1 1942    448
      1 1943  499.6
      1 1944  547.5
      1 1945  561.2
      1 1946  688.1
      1 1947  568.9
      1 1948  529.2
      1 1949  555.1
      1 1950  642.9
      1 1951  755.9
      1 1952  891.2
      1 1953 1304.4
      1 1954 1486.7
      2 1935  209.9
      2 1936  355.3
      2 1937  469.9
      2 1938  262.3
      2 1939  230.4
      2 1940  361.6
      2 1941  472.8
      2 1942  445.6
      2 1943  361.6
      2 1944  288.2
      2 1945  258.7
      2 1946  420.3
      2 1947  420.5
      2 1948  494.5
      2 1949  405.1
      2 1950  418.8
      2 1951  588.2
      2 1952  645.5
      2 1953    641
      2 1954  459.3
      3 1935   33.1
      3 1936     45
      3 1937   77.2
      3 1938   44.6
      3 1939   48.1
      3 1940   74.4
      3 1941    113
      3 1942   91.9
      3 1943   61.3
      3 1944   56.8
      3 1945   93.6
      3 1946  159.9
      3 1947  147.2
      3 1948  146.3
      3 1949   98.3
      3 1950   93.5
      3 1951  135.2
      3 1952  157.3
      3 1953  179.5
      3 1954  189.6
      4 1935  40.29
      4 1936  72.76
      4 1937  66.26
      4 1938   51.6
      4 1939  52.41
      4 1940  69.41
      4 1941  68.35
      4 1942   46.8
      4 1943   47.4
      4 1944  59.57
      4 1945  88.78
      4 1946  74.12
      4 1947  62.68
      4 1948  89.36
      4 1949  78.98
      4 1950 100.66
      4 1951 160.62
      4 1952    145
      4 1953 174.93
      4 1954 172.49
      5 1935  39.68
      5 1936  50.73
      5 1937  74.24
      5 1938  53.51
      5 1939  42.65
      5 1940  46.48
      5 1941   61.4
      5 1942  39.67
      5 1943  62.24
      5 1944  52.32
      5 1945  63.21
      5 1946  59.37
      5 1947  58.02
      5 1948  70.34
      5 1949  67.42
      5 1950  55.74
      5 1951   80.3
      5 1952   85.4
      5 1953   91.9
      5 1954  81.43
      end
      format %ty year
      How can I draw a bar graph for `invest' for each year like the one above? Thanks.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        You need to summarize the data first. Then as said start with twoway bar. Or consider first using statsby as in http://www.stata-journal.com/sjpdf.h...iclenum=gr0045 (but note that the syntax for ci has changed since that paper).

        Comment


        • #5
          I believe - serrbar - can present the situation "comme il faut", I mean, it can avoid the dynamite-plot's pitfalls.

          You may wish to try this:

          Code:
          statsby mean=r(mean) sd=r(sd) size=r(N), by(year):  summarize invest
          serrbar mean sd year
          Click image for larger version

Name:	Graph_serrbar2.png
Views:	1
Size:	30.9 KB
ID:	1436103

          Last edited by Marcos Almeida; 25 Mar 2018, 05:46. Reason: Crossed with Nick's reply.
          Best regards,

          Marcos

          Comment


          • #6
            Hi, Nick: Thank you. I will check it out.

            Ho-Chuan (River) Huang
            Stata 17.0, MP(4)

            Comment


            • #7
              Hi Marcos, Thanks for this interesting suggestion.
              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment


              • #8
                Stata code is
                Code:
                webuse grunfeld, clear
                statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(year) clear: ci mean invest
                twoway bar mean year, color(gs12) barw(0.5) || rcap ub lb year, legend(off)
                A figure is as follow:
                Click image for larger version

Name:	bar-with-ci-river.png
Views:	1
Size:	59.9 KB
ID:	1436168
                Ho-Chuan (River) Huang
                Stata 17.0, MP(4)

                Comment


                • #9
                  ssc install cibar provides a nice pre-packaged alternative

                  Comment


                  • #10
                    Dear Chris, Many thanks for suggesting this nice command.
                    Ho-Chuan (River) Huang
                    Stata 17.0, MP(4)

                    Comment

                    Working...
                    X