Announcement

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

  • Repeated measures mixed effect model - time depended calculation of marginal effects

    In a cross-over design every subject underwent treatment and placebo. During treatment/placebo and 10 minutes after we recorded the dependent variable. The dependent variable was recorded on a trial level. Time was coded with 0 (during) and 1 (after). Treatment as 0 (placebo) and 1 (active). Wins as 0 (low) and 1 (high). My aim is to put all data of assessments during and after in one model, because in a way measurements are dependent of each other. Therefore in a first step i used the following code.

    Code:
    mixed dependentvarialble treatment##time i.wins##i.treatment || id:, dfmethod(kroger) reml covariance(unstructured)
    Next I was interested in the marginal effects of active vs. placebo during low and high wins of either during (time=0) or after (time=1) treatment.

    Code:
    margin wins if time==0, dydx(treatment)
    margin wins if time==1, dydx(treatment)
    In your opinion, is this code correct to integrate the three variables time, treatment and wins?
    Last edited by Jasper Voeckel; 19 Dec 2023, 02:10.

  • #2
    I would do this as
    Code:
    margins wins#time, dydx(treatment)

    Comment


    • #3
      If I understand you correctly, it seems that you would want to model a 3-way interaction in the mixed model with treatment*time*wins. This allows time to moderate both the treatment and wins effect along with their interaction.
      Code:
      mixed dependentvarialble treatment##time##i.wins || id:, dfmethod(kroger) reml
      // covariance(unstructured) is not needed because you do not have a random slope
      From there, you can run the margins commands you specified. Those have the following interpretation:
      Code:
      margins wins if time==0, dydx(treatment)
      // marginal effect of treatment for each wins category only for those w/ time==0
      
      margins wins if time==1, dydx(treatment)
      // marginal effect of treatment for each wins category only for those w/ time==1
      Marginal effects can be even more powerful, in my opinion, if you utilize them to predict counterfactuals from your data. For example, if you did not specify time==0 or time==1 in your code above, and instead used something like:
      Code:
      margins wins#time, dydx(treatment)
      Margins estimates the treatment effect by giving all cases in your data not only their actual values on wins and time but also gives then other values for those variables that appear in the data. I highly recommend Richard Williams Stata Journal article on this topic. He gets into it in great detail but in a clear and concise way.
      Last edited by Erik Ruzek; 19 Dec 2023, 10:24. Reason: Crossed with #2, but it seems we are suggesting the same thing.

      Comment


      • #4
        Thanks a lot to both of you! This was very helpful.

        Comment

        Working...
        X