Announcement

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

  • How do I add error bars to my bar graph?

    I have three variables 'count_selectoptionsh' 'count_selectoptionsl' and 'treatment where the first two are count of high and low value options chosen by the participant. Treatment is just 1, 2 and 3 for three different treatments.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(count_selectoptionsh count_selectoptionsl) byte treatment
    1 2 2
    0 2 1
    5 1 2
    0 2 1
    3 2 1
    4 3 3
    2 2 3
    5 3 2
    1 1 3
    1 1 2
    2 3 1
    0 1 1
    1 1 2
    4 3 3
    0 2 1
    4 4 2
    1 2 1
    0 0 1
    4 4 2
    3 6 1
    2 3 1
    0 0 1
    1 3 2
    2 3 3
    0 0 1
    1 1 2
    3 1 1
    2 2 1
    1 3 2
    0 3 1
    1 4 1
    2 2 1
    3 3 1
    1 2 2
    2 1 3
    2 7 1
    2 4 3
    1 1 1
    5 3 1
    3 4 3
    3 3 2
    4 2 3
    7 5 1
    2 4 1
    0 0 1
    2 5 1
    4 5 2
    3 6 1
    4 6 2
    0 0 3
    2 2 2
    1 7 1
    1 1 3
    0 3 1
    1 1 3
    0 2 2
    4 3 2
    3 2 2
    3 7 3
    2 2 2
    2 2 3
    1 2 3
    1 2 1
    5 1 3
    7 0 2
    1 4 2
    2 4 2
    1 0 3
    2 2 2
    2 2 1
    4 5 2
    2 3 2
    2 5 1
    2 4 2
    3 4 1
    0 3 2
    1 1 3
    1 1 1
    1 1 3
    4 4 2
    2 3 3
    1 3 1
    1 2 1
    3 5 3
    1 0 3
    4 3 2
    2 4 2
    3 3 3
    0 0 3
    0 0 1
    1 1 1
    1 2 3
    1 2 3
    2 2 2
    2 5 3
    4 3 1
    7 2 2
    5 5 3
    1 0 3
    2 7 3
    end
    How do I generate two separate (and also combined) bar graphs for the mean of 'count_selectoptionsh' and 'count_selectoptionsl' by treatment with standard error bars?

    Thank you for your help!

  • #2
    Here is some token code. Search this forum for mentions of detonator, dynamite and plunger plots to see why I don't give bar chart code.

    See also https://journals.sagepub.com/doi/pdf...867X1001000112

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(count_selectoptionsh count_selectoptionsl) byte treatment
    1 2 2
    0 2 1
    5 1 2
    0 2 1
    3 2 1
    4 3 3
    2 2 3
    5 3 2
    1 1 3
    1 1 2
    2 3 1
    0 1 1
    1 1 2
    4 3 3
    0 2 1
    4 4 2
    1 2 1
    0 0 1
    4 4 2
    3 6 1
    2 3 1
    0 0 1
    1 3 2
    2 3 3
    0 0 1
    1 1 2
    3 1 1
    2 2 1
    1 3 2
    0 3 1
    1 4 1
    2 2 1
    3 3 1
    1 2 2
    2 1 3
    2 7 1
    2 4 3
    1 1 1
    5 3 1
    3 4 3
    3 3 2
    4 2 3
    7 5 1
    2 4 1
    0 0 1
    2 5 1
    4 5 2
    3 6 1
    4 6 2
    0 0 3
    2 2 2
    1 7 1
    1 1 3
    0 3 1
    1 1 3
    0 2 2
    4 3 2
    3 2 2
    3 7 3
    2 2 2
    2 2 3
    1 2 3
    1 2 1
    5 1 3
    7 0 2
    1 4 2
    2 4 2
    1 0 3
    2 2 2
    2 2 1
    4 5 2
    2 3 2
    2 5 1
    2 4 2
    3 4 1
    0 3 2
    1 1 3
    1 1 1
    1 1 3
    4 4 2
    2 3 3
    1 3 1
    1 2 1
    3 5 3
    1 0 3
    4 3 2
    2 4 2
    3 3 3
    0 0 3
    0 0 1
    1 1 1
    1 2 3
    1 2 3
    2 2 2
    2 5 3
    4 3 1
    7 2 2
    5 5 3
    1 0 3
    2 7 3
    end
    
    save your_data, replace
    
    statsby, by(treatment) : ci means count_selectoptionsh , poisson 
    
    gen which = "High"
    
    save results_h, replace 
    
    use your_data, clear 
    
    statsby, by(treatment) : ci means count_selectoptionsl, poisson 
    
    gen which = "Low"
    
    append using results_h 
    
    twoway scatter mean treatment, msize(large) ms(Dh) || rcap ub lb treatment, msize(large) by(which, subtitle(Means and 95% confidence intervals) note("") legend(off)) xla(1 "informative" 2 "text" 3 "here", tlc(none)) ytitle(Count of select options) xsc(r(0.5 3.5)) xtitle(Treatment)
    Click image for larger version

Name:	poisson_means.png
Views:	1
Size:	31.8 KB
ID:	1761232


    Comment

    Working...
    X