Announcement

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

  • Repeated Measures ANOVA

    I am unable to come up with a code to perform the Repeated Measures ANOVA for the following dataset:

    I have participants divided in two groups: 1 & 2. (variable name: Groups)
    Each group has a sub-group: 1 2 & 3 (variable name: Dosage)
    Observations for each participant are recorded at 3 time points: 1 2 & 3 (variable name: visit)
    Outcome variable: SBP
    Unique ID for participants: SrNo

    How do I perform the task?

  • #2
    Originally posted by Vaibhav Miglani View Post
    I am unable to come up with a code to perform the Repeated Measures ANOVA for the following dataset: . . . How do I perform the task?
    See below. Begin at the "Begin here" comment; the stuff above is just to create an illustrative dataset that matches your description. Do-file and log file are attached if further interest.
    Code:
    version 18.0
    
    clear *
    
    // seedem
    set seed 2050902133
    
    // "Unique ID for participants: SrNo""
    quietly set obs 24
    generate byte SrNo = _n
    generate double u = rnormal()
    
    // "I have participants divided in two groups: 1 & 2. (variable name: Groups)"
    generate byte Groups = mod(_n, 2)
    
    // "Each group has a sub-group: 1 2 & 3 (variable name: Dosage)"
    sort Groups SrNo
    egen byte Dosage = fill(1 2 3 1 2 3)
    list SrNo Groups Dosage, noobs sepby(Groups)
    
    // Observations for each participant are recorded at 3 time points: 1 2 & 3 (variable name: visit)
    quietly expand 3
    bysort SrNo: generate byte visit = _n
    
    // Outcome variable: SBP
    generate double SBP = u + rnormal()
    
    *
    * Begin here
    *
    rename *, lower
    
    anova sbp i.groups##i.dosage / srno|i.groups#i.dosage i.visit ///
        i.groups#i.visit i.dosage#i.visit i.groups#i.dosage#i.visit, repeated(visit)
    
    // Alternatively
    mixed sbp i.groups##i.dosage##i.visit || srno: , reml dfmethod(kroger) ///
        nolrtest nolog
    contrast groups dosage visit groups#dosage groups#visit dosage#visit ///
        groups#dosage#visit, small
    
    exit
    Attached Files

    Comment

    Working...
    X