Announcement

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

  • how to: multiple subpops and means

    Hi all,

    I am trying to calculate mean intake of XXX (within survey estimates) and can do this for subpopulations like age and gender (e.g. can do mean of XXX among males and females, can do mean of XXX among children and adults). However, I cannot work out how to do the means among both age and gender at the same time (e.g. how can I do mean of XXX among adult females etc.).

    Any help would be greatly appreciated.

    Thanks!
    Cassandra

  • #2
    Hi Cassandra,

    I hope this answers your question.

    bysort Sex :sum(XXX) if adult==1

    Hopefully, with the syntax/command above, you will be able to get your mean of XXX among adult females as well as adult males respectively.

    Comment


    • #3
      To add to Emerald's witty post (very nice), it is not clear if you want to number as an output or to create a variable with the number.

      I'd normally think about bysort sex age: egen meanxxx=mean(xxx)

      or bysort sex age: su xxx

      There is also a way to do this with table or tabstat.

      Comment


      • #4
        Because you have survey data, you must svyset the data first. Otherwise Stata will not weight the observations properly and will estimate incorrect standard errrors. Then:
        Code:
        svy: mean XXX, over(sex age)
        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment


        • #5
          Thank you all for your reply.
          And thanks very much Steve, the code works perfectly!

          Comment

          Working...
          X