Announcement

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

  • ttest with 'by' options

    Hello, I have a chart of my variable "score" which is presented stratifying by sex and by age-group.
    I would like to compare the score between men and women, for each age group separately. I will thus use 4 t-tests.
    I am finding it hard to generate the code. So far I have used

    ttest score, by(sex) if age_grp==1
    ttest score, by(sex) if age_grp==2
    ttest score, by(sex) if age_grp==3
    ttest score, by(sex) if age_grp==4

    but I keep getting the message that the option [if] if not allowed. I suppose I could do a Factorial ANOVA, but I am really trying to understand whether Score varies by sex, separately in each agegroup.


    Age
    Group
    N men
    (2299)
    Score Men
    Mean(SD)
    N women
    (4762)
    Score Women
    Mean(SD)
    P value*
    <60 187 16.54(3.34) 324 15.86(2.95)
    60-69 1028 16.91(3.57) 1426 16.78(3.37)
    70-79 846 17.07(3.60) 885 16.89(3.39)
    >80 238 17.48(3.91) 212 16.76(3.51)





  • #2
    Look at the help for ttest. An if qualifier is not an option and should be specified before the comma. (There is an exception to this, but it would be a distraction to explain it.)

    Code:
    ttest score if age_grp==1, by(sex)

    Comment


    • #3
      Alan:
      the -if- qualifier is misplaced in your code.
      Try something along the following lines, instead:
      Code:
      ttest score if age_grp==1, by(sex) unequal *-unequal- option relaxes the often untenable assumption of equal variance*
      PS: late to the party once more!

      A different take would consider switching to regression, interacting -sex- with -age_grp-:
      Code:
      regress score i.sex##i.age_grp
      Last edited by Carlo Lazzaro; 05 Jul 2018, 11:10.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Also late. With 4 comparisons you may take in consideration adjustments for familywise error. in short, as pointed out before, linear regression or ANOVA seem to be the best approach.
        Best regards,

        Marcos

        Comment

        Working...
        X