Announcement

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

  • margins with xtset and lagged variables

    Hi all, I'm posting without any data because I think this is a conceptual rather than technical question (Stata 17.0).

    I'm happy using margins after xtset and looking at effect of lagged exposure variable and interaction with categorical variable on current outcome, e.g.:
    Code:
    sort pid time
    xtset pid time
    regress panel_zscore c.L1.panel_zscore##i.binary, cluster(pid)
    margins, at(binary=(0 1) l.panel_zscore=(-2(2)2))
    This is great, giving me values of panel_zscore (y axis) as a function of the previous score (3 strata taking values -2SD, 0 and +2SD), depending on whether binary occurred or not (x axis).

    I'd like to see the change in panel_zscore over time (which is not directly in the model <- it's embedded in xtset), such that the marginsplot would give:

    panel_zscore (y axis) by(binary) as it changes from one lagged measure to the outcome such that time in the x axis.
    (I put by(binary) in italics as it's obviously not a real command, it expresses what I'm hoping for).

    This example would give 6 lines showing change from lagged measure to follow-up: one for each marginal level (-2SD, 0 and +2SD) * binary status.

    Is this possible using marginsplot, or do I need to use something like predict instead?

    Many thanks in advance.
    Last edited by Daniel Davis UCL; 13 Sep 2022, 04:05.

  • #2
    I am not sure about why you need to xtset this data if you are not using the xt set of commands. Perhaps to get the lagged panel score?

    Margins is using predict behind the scenes to get you the panel_zscore at the conditions you specify. The challenge is that you do not have time in your model; thus even the predict approach would have issues because predict is based on the values on the covariates in your model. If time is important, then it seems you need to model it. or if you are only curious about the time trend, then just look at that descriptively?

    Comment

    Working...
    X