Announcement

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

  • Simple effect tests following two-way ANCOVA

    Hi everyone,

    I am currently working on a research project in which I run a two-way ANCOVA with one covariate. Both variables of interest (a and b) are categorical (with two levels each), and the covariate d is continuous. I used the following code: anova y a##b c.d

    Now my question is about the test of simple main effects. The ANCOVA shows a significant interaction of a and b and a significant main effect of b, so I want to do simple main effect tests to see whether b is significant in both levels of a or just in one of the two. How can I do this in Stata? The covariate d still needs to be included, otherwise commands like sme do not seem to work (I tried "sme b a" and it showed no significant effect of b for either level of a, and I think this is because I did not manage to include the covariate in this simple main effect test; however, I am happy to use other commands than sme if there are better ones!).

    Thanks in advance!

  • #2
    Have you considered contrast or margins?

    .ÿ
    .ÿversionÿ16.1

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿsetÿseedÿ`=strreverse("1547282")'

    .ÿ
    .ÿquietlyÿsetÿobsÿ28

    .ÿgenerateÿbyteÿAÿ=ÿmod(_n,ÿ2)

    .ÿbysortÿA:ÿgenerateÿbyteÿBÿ=ÿmod(_n,ÿ2)

    .ÿ
    .ÿgenerateÿdoubleÿCÿ=ÿruniform(-0.5,ÿ0.5)

    .ÿ
    .ÿgenerateÿdoubleÿoutÿ=ÿrnormal()

    .ÿ
    .ÿ*
    .ÿ*ÿBeginÿhere
    .ÿ*
    .ÿanovaÿoutÿi.A##i.Bÿc.C

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿÿÿÿÿÿÿÿÿ28ÿÿÿÿR-squaredÿÿÿÿÿ=ÿÿ0.2054
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿRootÿMSEÿÿÿÿÿÿ=ÿÿÿÿ1.03243ÿÿÿÿAdjÿR-squaredÿ=ÿÿ0.0672

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿPartialÿSSÿÿÿÿÿÿÿÿÿdfÿÿÿÿÿÿÿÿÿMSÿÿÿÿÿÿÿÿFÿÿÿÿProb>F
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-----------+----------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿModelÿ|ÿÿ6.3368733ÿÿÿÿÿÿÿÿÿÿ4ÿÿÿ1.5842183ÿÿÿÿÿÿ1.49ÿÿ0.2390
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿAÿ|ÿÿ.00322125ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ.00322125ÿÿÿÿÿÿ0.00ÿÿ0.9566
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿBÿ|ÿÿ4.0071408ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ4.0071408ÿÿÿÿÿÿ3.76ÿÿ0.0649
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿA#Bÿ|ÿÿÿ.0125271ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿ.0125271ÿÿÿÿÿÿ0.01ÿÿ0.9146
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿCÿ|ÿÿ1.4485264ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿ1.4485264ÿÿÿÿÿÿ1.36ÿÿ0.2557
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿ24.516175ÿÿÿÿÿÿÿÿÿ23ÿÿÿ1.0659207ÿÿ
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-----------+----------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿTotalÿ|ÿÿ30.853048ÿÿÿÿÿÿÿÿÿ27ÿÿÿ1.1427055ÿÿ

    .ÿ
    .ÿcontrastÿr.B@A,ÿnoeffects

    Contrastsÿofÿmarginalÿlinearÿpredictions

    Marginsÿÿÿÿÿÿ:ÿasbalanced

    ------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿdfÿÿÿÿÿÿÿÿÿÿÿFÿÿÿÿÿÿÿÿP>F
    -------------+----------------------------------
    ÿÿÿÿÿÿÿÿÿB@Aÿ|
    ÿ(1ÿvsÿ0)ÿ0ÿÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿ2.04ÿÿÿÿÿ0.1669
    ÿ(1ÿvsÿ0)ÿ1ÿÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿÿÿ1.69ÿÿÿÿÿ0.2063
    ÿÿÿÿÿÿJointÿÿ|ÿÿÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿ1.88ÿÿÿÿÿ0.1750
    ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿDenominatorÿ|ÿÿÿÿÿÿÿÿÿ23
    ------------------------------------------------

    .ÿ
    .ÿquietlyÿmarginsÿA#B,ÿpost

    .ÿtestÿ0.A#1.Bÿ=ÿ0.A#0.B

    ÿ(ÿ1)ÿÿ-ÿ0bn.A#0bn.Bÿ+ÿ0bn.A#1.Bÿ=ÿ0

    ÿÿÿÿÿÿÿF(ÿÿ1,ÿÿÿÿ23)ÿ=ÿÿÿÿ2.04
    ÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿFÿ=ÿÿÿÿ0.1669

    .ÿtestÿ1.A#1.Bÿ=ÿ1.A#0.B

    ÿ(ÿ1)ÿÿ-ÿ1.A#0bn.Bÿ+ÿ1.A#1.Bÿ=ÿ0

    ÿÿÿÿÿÿÿF(ÿÿ1,ÿÿÿÿ23)ÿ=ÿÿÿÿ1.69
    ÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿFÿ=ÿÿÿÿ0.2063

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .

    Comment


    • #3
      Thanks for the reply! I tried both options and still the simple main effects of B remain insignificant. However, I realized that in your example from above, the p values of B are higher than the p value in the ANOVA table (p = 0.1669 and p = 0.2063 vs. p = 0.0649), like in my case. I also observed that the sme command I originally used yields the same F value as both contrast and margins command, so these three tests seem to tell me the same about the effect of B in both levels of A.
      But I am still wondering whether these outputs are misleading because these commands exclude the covariate (which was significant at p < .001 in the ANOVA) or whether they are not (and already include the covariate) and I am just wrong in expecting to observe one or two significant simple main effects of B because of a significant main effect of B in the ANOVA (if the latter is true, could you maybe tell me how this is possible?).

      Comment

      Working...
      X