Announcement

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

  • Repeated measures ANOVA

    Dear Statalist,

    I'm currently trying to replicate a piece of analysis originally done on SPSS in Stata 17 (Mac OS); specifically, a repeated-measures ANOVA.

    The original SPSS code is:

    Code:
    GLM confrontT1 confrontT3 WITH changeconfrontCOVID  
    /WSFACTOR=toename_confront_speed 2 Polynomial    
      /METHOD=SSTYPE(3)    
       /EMMEANS=TABLES(toename_confront_speed) WITH(changeconfrontCOVID=-30)COMPARE ADJ(LSD)    
       /EMMEANS=TABLES(toename_confront_speed) WITH(changeconfrontCOVID=0)COMPARE ADJ(LSD)    
       /EMMEANS=TABLES(toename_confront_speed) WITH(changeconfrontCOVID=30)COMPARE ADJ(LSD)  
     /PRINT=DESCRIPTIVE ETASQ    
     /CRITERIA=ALPHA(.05)  
     /WSDESIGN=toename_confront_speed    
     /DESIGN=changeconfrontCOVID.
    The variables confrontT1 and confrontT3 are measures of intention to confront individuals who violate a social norm measured at time 1 and 3; changeconfrontCOVID is a control variable about perceptions a Covid-related norm.

    The analysis was done on a dataset in wide format. I first reshaped the dataset into long format. The variables "confrontT1" and "confrontT3" are now "confrontT", "real_id" is an individual identifier, and "t" is time. The variable changeconfrontCOVID is a non-integer ranging from -100 to 100. A sample of the long format dataset is below,

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double confrontT float real_id byte t double changeconfrontCOVID
      5  3 1 -29.5
      4  3 3 -29.5
      6  5 1    18
      6  5 3    18
    4.5  7 1     .
      1  7 3     .
      6 19 1  -7.5
      7 19 3  -7.5
    1.5 21 1    30
    1.5 21 3    30
      5 23 1   -65
    3.5 23 3   -65
      1 24 1  22.5
      1 24 3  22.5
      4 32 1    62
    end
    Based on the Stata documentation, I believe the correct syntax should be:

    Code:
    anova confrontT c.changeconfrontCOVID / i.real_id | c.changeconfrontCOVID t c.changeconfrontCOVID#t, repeat(t)
    However, I get the error message

    invalid interaction specification;
    '|' requires a factor variable on each side
    If I remove the factor-variable operators and type real_id | changeconfrontCOVID, I get the following error message

    changeconfrontCOVID: factor variables may not contain noninteger values
    I was wondering if you could tell me how to work around this issue. I would be grateful for any help.

    Best regards,
    Miguel Fonseca

  • #2
    Originally posted by Miguel Fonseca View Post
    I was wondering if you could tell me how to work around this issue.
    Easiest:
    Code:
    mixed confrontT c.changeconfrontCOVID##i.t || real_id: , reml dfmethod(kroger) nolrtest nolog
    If your dataset is balanced (your snippet isn't) and if you don't mind ignoring the test statistic for the covariate, then
    Code:
    anova confrontT c.changeconfrontCOVID / real_id t c.changeconfrontCOVID#t
    the repeated() option being unnecessary with two measurements.
    Last edited by Joseph Coveney; 23 May 2023, 20:46.

    Comment


    • #3
      Many thanks Joseph. Both approaches exactly replicate the original results except for the covariate, where I get a different test statistic (about a quarter of that reported in the original analysis). I understand why the anova command gives a different test statistic, not sure why the first approach did not. On the right track, anyway.

      Comment


      • #4
        Originally posted by Miguel Fonseca View Post
        Both approaches exactly replicate the original results except for the covariate, where I get a different test statistic (about a quarter of that reported in the original analysis).
        You might want to make sure that your model specification matches the original's in SPSS in particular with respect to how the within-subject time-invariant continuous covariate is modeled.

        Comment

        Working...
        X