Announcement

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

  • Performing multiple anova commands with subsequent pwcompare

    Hello,

    I'm using Stata/SE 17.0 in Windows and have a dataset with 1048 observations of four variables: a single continuous variable (dep), and three categorical variables (var_a, var_b, var_c).
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float dep byte(var_a var_b var_c)
     -1.473198 8 3 1
    -1.3605777 4 2 2
    -1.3252764 4 2 2
    -1.2028136 4 3 2
    -1.1625886 4 1 2
    -1.1346984 1 1 2
    end
    var_a and var_b have three levels, var_c has two

    I'm interested in determining whether, for each combination of var_b and var_c, there are differences in dep across each pairwise comparison of var_a. My approach has been to use anova:
    Code:
    by var_b var_c, sort: anova dep var_a
    which repeats the command six times and so I've omitted the rather lengthy output. To get corrected p-values for a single anova, I would use pwcompare:
    Code:
    pwcompare var_a, pveffects mcompare(sidak)
    
    Pairwise comparisons of marginal linear predictions
    
    Margins: asbalanced
    
    ---------------------------
                 |    Number of
                 |  comparisons
    -------------+-------------
           var_a |            3
    ---------------------------
    
    -----------------------------------------------------
                 |                              Sidak
                 |   Contrast   Std. err.      t    P>|t|
    -------------+---------------------------------------
           var_a |
         4 vs 1  |  -.4028051   .0839929    -4.80   0.000
         8 vs 1  |  -.5907805   .0888898    -6.65   0.000
         8 vs 4  |  -.1879754   .0929252    -2.02   0.128
    -----------------------------------------------------
    However, because I've asked Stata to iterate over var_b and var_c, I cannot use pwcompare (I don't think) because its output will represent only the last iteration of the repeating anova command. In this instance, I could instead run six individual anova and pwcompare commands and get the values I'm looking for. Not too painful.

    However, what if my variables had more levels, making this difficult or impossible? Is there a built-in way to have Stata do pairwise comparisons for many anova commands without writing a function? (I haven't had to learn programming in Stata thanks in large part to the available community packages) Is there an alternative to anova that would work for my purpose?

    In addition, it seems appropriate to correct for multiple comparisons by considering ALL comparisons I've performed, not just the number within each anova command. Is that possible with an existing command?

    Thanks in advance,
    Adam

    P.S. This is my first post and I'm genuinely interested in criticisms regarding topic and format so as to improve future posts!
    Last edited by Adam Zahm; 09 Feb 2023, 13:53.

  • #2
    In addition, it seems appropriate to correct for multiple comparisons by considering ALL comparisons I've performed, not just the number within each anova command. Is that possible with an existing command?
    It seems I should save all uncorrected p-values from the pwcompare and then use the 'qqvalue' package for correction.

    Comment

    Working...
    X