Announcement

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

  • Overlaying twoway bar graphs - bars side-by-side not overlaid

    Hi, I realise this is most likely an elementary question, but I cannot find a solution. I would like the to overlay the following twoway graphs with each pair of bars side-by-side as shown in the pictures. I have also attached what my current graph looks like.

    I have used the command:

    twoway (bar adultcases year, barwidth(0.5)) (bar childcases year, barwidth(0.5))

    Thanks,

    Scott

    Attached Files

  • #2
    SJ-7-1 gr0026 . . . . Stata tip 42: The overlay problem: Offset for clarity
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . J. Cui
    Q1/07 SJ 7(1):141--142 (no commands)
    tip for graphing several quantities on a continuous axis


    http://www.stata-journal.com/sjpdf.h...iclenum=gr0026

    Comment


    • #3
      Many thanks Mr Cox, I have got my graph, you have been a great help.

      Comment


      • #4
        Thank you Nick Cox for introducing James Cui's tips. I just wonder whether Stata could do the offset work automatically like in Excel, say adding a new option of offset (twoway bar yvar xvar, offset), it would seems more smart.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input int year double visit str15 group double(dep sddep n n2 high low sderror1 sderror2)
        2016 1 "Placebo"  16.48 5.28 27 20 18.51 14.45 2.04 2.36
        2017 1 "Estrogen" 13.37 5.56 34 89 15.28 11.46 1.92 1.18
        2018 2 "Placebo"  15.89 6.12 22 58  18.5 13.28 2.61 1.61
        2019 2 "Estrogen" 11.74 6.58 31 37  14.1  9.38 2.36 2.16
        2020 3 "Placebo"  14.13 4.97 17 85 16.54 11.72 2.41 1.08
        2021 3 "Estrogen"  9.13 5.48 29 39 11.17  7.09 2.04 1.76
        2022 4 "Placebo"  12.27 5.85 17 12 15.11  9.43 2.84 3.38
        2023 4 "Estrogen"  8.83 4.67 28 75  10.6  7.06 1.77 1.08
        2024 5 "Placebo"   11.4 4.44 17 70 13.55  9.25 2.15 1.06
        2025 5 "Estrogen"  7.31 5.74 28 69  9.48  5.14 2.17 1.37
        end
        Code:
        gen year1=year-0.2
        gen year2=year+0.2
        twoway bar high year1, barwidth(0.4) || ///
               bar low year2, barwidth(0.4) xlabel(2016(1)2025) xtitle("") || ///
               conn sderror1 sderror2 year, yaxis(2) ylabel(0(1)3, axis(2)) legend(row(1) pos(6))
        Click image for larger version

Name:	excelstata.png
Views:	1
Size:	79.2 KB
ID:	1780795

        Comment


        • #5
          Chen Samulsion That's a suggestion for StataCorp. I would put it in a different thread.

          In this particular case, I wouldn't put high and low side by side in any case, but that's a quite different point.

          Comment

          Working...
          X