Announcement

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

  • Run anova on specific sets of cases

    Hello,
    I've searched and searched but could not find the answer to this.

    Here is an example data set:
    Person Condition Score
    1 Treatment 1 45
    2 Control 88
    3 Treatment 1 23
    4 Treatment 2 23
    5 Control 59
    6 Treatment 2 84
    For example, If I wanted to look at the variance in scores between just those in the Treatment 1 and Treatment 2, how would I specify those after the anova command?

    Thank you for your time
    Last edited by butler bj; 03 Apr 2015, 12:25.

  • #2
    If you mean, how would you do the ANOVA only on those observations where Condition = Treatment 1 or Condition = Treatment 2, it's just:

    Code:
    anova score condition if inlist(Condition, "Treatment 1", "Treatment 2")
    Note: assumes that Condition is a string variable, not a numeric variable with value labels.

    Do read the User's Guide section about -if- conditions: [U] 11.1.3, including the examples shown there. It's a very fundamental part of Stata syntax and you will find it indispensable going forward.

    Comment


    • #3
      Code:
      ttest score if Condition!="Control", by(Condition)

      Comment


      • #4


        Perhaps some information on the commands related to - contrasts - (http://www.stata.com/manuals13/rcontrast.pdf) as well as -margins - (http://www.ats.ucla.edu/stat/stata/f...omparisons.htm) would please you.

        Anyway, I wonder whether you in fact wouldn't rather perform a post-hoc pairwise comparison after Anova, and here I share useful information (http://www.ats.ucla.edu/stat/stata/faq/pairwiseadj.htm)..

        Best,

        Marcos
        Best regards,

        Marcos

        Comment


        • #5
          Thank you both for the replies. I forgot to specify one important part of my question; I am interested in the differences in Males in Treatment 1 vs. Females in Treatment 2
          I have updated the table below:
          Person Condition Score Gender
          1 Treatment 1 45 M (1)
          2 Control 88 F (2)
          3 Treatment 1 23 M
          4 Treatment 2 23 M
          5 Control 59 F
          6 Treatment 2 84 F

          if I run
          Code:
           
           ttest score if Condition!="Control", by(Gender)
          I get the differences between Genders in the two Treatment Groups but now drilled down to Males in Treatment 1 vs. Females in Treatment 2.

          Clyde: I read the Chapter in the user guide, but I could not figure out what I am trying to accomplish. I have been trying different if/& combinations but have been unsuccessful.

          Comment


          • #6
            Code:
            gen byte include = (Condition == "Treatment 1" & Gender == "M") | (condition == "Treatment 2" & Gender == "F")
            ttest Score if include, by(Gender)
            Notes:

            I can't tell from your post whether Gender is a string variable or a numeric variable with value labels. The above assumes it's a string variable coded M or F only.

            The output of -ttest- will not make any reference to Condition, only to Gender. But given the definition of the include variable, Male will, in this context, imply Treatment 1, and Female will imply Treatment 2.
            Last edited by Clyde Schechter; 03 Apr 2015, 14:23.

            Comment


            • #7
              Originally posted by Clyde Schechter View Post
              Code:
              gen byte include = (Condition == "Treatment 1" & Gender == "M") | (condition == "Treatment 2" & Gender == "F")
              ttest Score if include, by(Gender)
              Notes:

              I can't tell from your post whether Gender is a string variable or a numeric variable with value labels. The above assumes it's a string variable coded M or F only.

              The output of -ttest- will not make any reference to Condition, only to Gender. But given the definition of the include variable, Male will, in this context, imply Treatment 1, and Female will imply Treatment 2.
              Thank you for your help! I was able to run the analyses.

              Now, for my own understanding two (hopefully) final questions:
              1) When you created the byte include, is the first parameter (Condition == "Treatment 1" & Gender == "M") coded as 0 and the second (condition == "Treatment 2" & Gender == "F") coded as 1?
              2) what does the if statement mean in the ttest command?

              Thank you all again for the great help

              Comment


              • #8
                Now, for my own understanding two (hopefully) final questions:
                1) When you created the byte include, is the first parameter (Condition == "Treatment 1" & Gender == "M") coded as 0 and the second (condition == "Treatment 2" & Gender == "F") coded as 1?
                2) what does the if statement mean in the ttest command?
                You're welcome.

                1. No, include is coded as 1 for those observations in which condition = Treatment 1 and Gender = M, or in which condition = Treatment 2 and gender = F. In all other observations (i.e. those that meet neither condition), include = 0. The vertical stroke (|) is how you say OR in Stata. Please read [U] 13.2.4 for more information about logical operators in Stata.

                2. Reread [U] 11.1.3. I don't know how to say it any more clearly than what is there.

                Comment

                Working...
                X