Announcement

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

  • Bar plot comparing multiple variables among two groups

    Hi all,

    I am trying to draw a bar plot comparing multiple variables among two groups. var1 is the group indicator (1 or 2). The figure should have four bars. From left to right, the mean of var2 in group 1, the mean of var2 in group 2, the mean of var3 in group 1, and the mean of var3 in group 2. The first bar and second bar are side-by-side, so are the third and fourth bars. There is a gap between the second and the third bar. The first and third bars use one color (red), while the second and fourth bars use another color (blue).

    Thank you in advance.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(var1 var2 var3)
    1 1 1
    1 0 0
    1 1 0
    1 1 0
    2 0 1
    2 0 1
    2 0 1
    2 1 0
    end

  • #2
    You can do this with statplot from SSC. statplot is a good search term to find several discussions here on Statalist.


    Code:
    clear
    input float(var1 var2 var3)
    1 1 1
    1 0 0
    1 1 0
    1 1 0
    2 0 1
    2 0 1
    2 0 1
    2 1 0
    end
    
    * a fairly standard plot, which is not what you want 
    graph bar var2 var3, over(var1) bar(1, color(red)) bar(2, color(blue))
    
    ssc inst statplot 
    
    statplot var2 var3, over(var1)  asyvars bar(1, color(red)) bar(2, color(blue)) recast(bar)
    Note that "Thanks in advance" divides the world. See e.g. https://www.businesswritingblog.com/...n-advance.html

    Comment


    • #3
      Thank you, Nick.

      Comment

      Working...
      X