Announcement

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

  • how to graph using "tab" function

    I am trying to make a bar graph of the mean heights over different age groups and over different sexes. I can get the mean height for each age group using "tab Age, sum(Height)" or using "mean(Height), over(Age)" but when I try to do "mean(Height), over(Age), over(Sex)" I get an error. I've also tried doing "graph bar Height, over(Age), by(Sex)" but that also gave me an error. Can someone help me to separate my data by sex and then find the mean heights for each age? I basically need one graph showing the mean heights for females at each age, and another showing the mean heights for males at each age. Thanks!
    Last edited by Eve Martin; 08 Sep 2018, 17:47.

  • #2
    Let's review basic Stata command syntax. In Stata, there is a comma separating the main command from the options, but there cannot be additional commas separating options from each other. You also need to review each individual command to see what options it allows. -graph bar- allows an -over()- option, and you can even have more than one -over()- option in the same command. But -graph bar- does not support a -by()- option. -mean- allows an -over()- option, but it cannot be repeated, so it is not useful for your current situation.

    For your present purposes
    Code:
    graph bar Height, over(Age) over(Sex)
    will serve. (You may prefer to change the order of the two -over()- options to get the bars in the order you want.) Notice that it is two -over()- options, no -by()-, and no comma separating the -over()- options.

    If you just want to display the means by age and sex, but not graph them, you have several choices, including
    Code:
    tab Age Sex, summ(Height)
    table Age Sex, c(mean Height)

    Comment

    Working...
    X