Announcement

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

  • Bar graph showing percentages in each category

    I have:
    Y X
    1 1
    1 0
    1 1
    2 1
    2 0

    I want to have a bar graphs that displays two bars for each value of Y variable, displaying percentage of X=1 for each category.

    graph bar (percent) X, over(Y) produces this (not sure what the utility of that is):
    1 60%
    2 40%

    graph bar X, over(Y) produces this:
    1 0.67
    2 0.5

    I cannot find out how to make what I want:
    1 67%
    2 50%

    Is there a clear and easy way to do that with bar graph command without creating any more variables?

  • #2
    graph bar X, over(Y) produces this:
    1 0.67
    2 0.5

    I cannot find out how to make what I want:
    1 67%
    2 50%

    Is there a clear and easy way to do that with bar graph command without creating any more variables?
    As you show here, the mean of a 0/1 variable is a proportion, so you already have what you want. All that you have to do is to adjust the axis labels (i.e., multiply by 100).

    Comment


    • #3
      graph bar defaults to showing means. Multiply X by 100 and your means become percents in this case.


      Code:
      gen X2 = 100 * X 
      label var X2 "X" 
      graph bar X2, over(Y)

      Comment

      Working...
      X