Announcement

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

  • How can I change the order of the bars in this bar graph?

    I am a beginner Stata user. For a research project, whose information I must unfortunately keep confidential, I am trying to adjust a bar graph so that the order of the bars are "Increase", "Same", "Decrease" instead of the default alphabetical "Decrease", "Increase", "Same".

    To create this graph, I load in my cleaned dataset and run:

    Code:
     graph bar, by(byvar) over(groupvar)
    In an attempt to try to re-order the bars, I ran:

    Code:
    gen order=1 if groupvar=="Increase"
    replace order=2 if groupvar=="Same"
    replace order=3 if groupvar=="Decrease"
    graph bar, by(byvar) over(groupvar, sort(order)) .
    I get the error message "variable mean not found".

    How should I fix this?

    (Apologies if this is too difficult to answer without being able to see the graph and data.)
    Last edited by Noah Spencer; 11 Jan 2019, 17:43.

  • #2
    I figured it out! The issue is just that you need to include a y variable. I just included age (not related to anything I was showing in the graph, but I had data on it for all observations.

    Code:
      
     graph bar (percent) yvar, by(byvar) over(groupvar, sort(order))

    Comment

    Working...
    X