Announcement

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

  • Side by side bars for twoway bar graph

    Hello Statalist,

    I am having trouble with something that I thought would be quite basic. I need to compare 3 continuous variables over time using a bar graph. Below is my my example data and code I used to generate the attached graph.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year float(estimate est_ci_l est_ci_u control1 control2)
    2015  87416.73 63665.59 112986.24     . 36537
    2016   99954.7 87768.51 111265.88 65682 60565
    2017  85363.24 62662.84 105752.55 52759 50769
    2018 122436.16 82525.18  158504.7 53547 56494
    end
    
    
    
    twoway bar estimate year , barw(0.3) || (rcap est_ci_u est_ci_l year) || bar control1 year, barw(0.3) || bar control2 year, barw(0.3)
    Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	33.2 KB
ID:	1563111

    I have an estimate of interest with its 95% confidence intervals and I need to compare it to two controls that do not have 95% CIs. How can I prevent the bars from being overlaid as above and display them side by side? I have seen in past posts that an offset option can be used but my Stata version 14.2 says the option is not allowed. Any help would be appreciated.

    Thank you

  • #2
    There is no offset option in Stata 16.1 either. I suspect the past posts you are alluding to were just based on creating their own offsets directly, as in say


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year float(estimate est_ci_l est_ci_u control1 control2)
    2015  87416.73 63665.59 112986.24     . 36537
    2016   99954.7 87768.51 111265.88 65682 60565
    2017  85363.24 62662.84 105752.55 52759 50769
    2018 122436.16 82525.18  158504.7 53547 56494
    end
    
    
    gen year1 = year - 0.2
    gen year2 = year + 0.2 
    
    twoway bar estimate year , barw(0.2) base(0) || rcap est_ci_u est_ci_l year || bar control1 year1, barw(0.2) || bar control2 year2, barw(0.2)

    Comment


    • #3
      Now I understand. Thank you very much Dr. Cox.

      Comment

      Working...
      X