Announcement

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

  • generating a bar graph with mean scores, over 2 variables

    Hello.


    I am trying to create a bar graph that has multiple groups, with the X axis categorized by age intervals (10-20, 20-30...) and within each age interval, show the average Go Score, with standard error bars, in both males and females.


    My variables are as follows:
    age_5 = age group in 5 year increments
    sex (m=0 / f=1)
    Go_score (independent variable).

    I have tried the following code:

    graph bar go_score, over(sex) over(age_5yearinc) which works nicely, but I would also like the graph to have error bars, and this unfortunately I have found to be very difficult.
    Attached Files

  • #2
    You'll need to switch to twoway bar in combination with twoway rcap to get what I guess you want. But there are plenty of alternative displays that show more of the data too, e.g. using stripplot (SSC).

    Comment


    • #3
      cibar (SSC) is a nice pre-packaged alternative

      Comment


      • #4
        Originally posted by Nick Cox View Post
        You'll need to switch to twoway bar in combination with twoway rcap to get what I guess you want. But there are plenty of alternative displays that show more of the data too, e.g. using stripplot (SSC).
        These are extremely helpful and produced exactly what I am looking for. Thanks, Nick & Chris.
        I have a very basic question: my age group variable on the x axis reads "1, 2, 3, 4" but what I would really like it to say is "25-35, 35-45, 45-55 etc". Is there something I can add to my code to produce this? Similarly, for male and female the legend says "0 and 1" but I would prefer it to actually specify "male and female"

        Thanks!

        Comment


        • #5
          You can manually input x-label options depending the graph command you're using (showing us, and sharing a snippet of your data would get you a better response - as indicated in the FAQs). A better approach though, is probably to label your age variable appropriately and the graph should pick it up (possibly depending on the use of available options).

          So you'd write

          Code:
          *For your age var
          label define agelabel 1"25-35" 2"35-45" 3"45-55" 4"55-65", replace
          label values age agelabel //obviously change where it says 'age' if your age variable is called something else
          
          *For your gender var
          label define genderlabel 0"Male" 1"Female", replace
          label values gender genderlabel
          
          *Re-run graph command
          ....
          A secondary point, your age categories overlap. If your data actually does overlap then you probably want to make new categories before labelling. You'll then want to make the label values 25-34, 35-44, 45-54, etc. If the data does not overlap, then you've just suggested incorrect labels and you can go straight to the correct ones without making a new variable first

          Comment

          Working...
          X