Announcement

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

  • Plotting results from nonlinear effects

    I am looking at how my outcome y evolves over time assuming such evolution may differ by x (binary).
    I assume a nonlinear effect of time, which I operationalize as a quadratic effect.
    Therefore I have time and time squared in my model, and I interact x with time, so my model looks like
    xtreg y time##x timesquare##x, i(pid)

    How can I plot y trajectories over time by x?
    In a model with a linear effect of time or where I treat time with dummies for each time point I would use “marginsplot” as below…but I cannot figure out how to correctly apply that in the case of a quadratic effect.
    xtreg y x##c.time, i(pid) /*or i.time if I want dummies for each time*/
    margins x, at(time=(0(5)50))
    marginsplot


    thanks. Any suggestions is welcome.
    Anna

  • #2
    Originally posted by Anna Manzoni View Post
    How can I plot y trajectories over time by x?
    In a model with a linear effect of time . . . I would use “marginsplot” as below…but I cannot figure out how to correctly apply that in the case of a quadratic effect.
    Use the factor variable notation for the quadratic term, as well.
    Code:
    xtreg y i.x##c.time##c.time, i(pid) re
    margins x, at(time = (0(5)50)
    marginsplot

    Comment


    • #3
      thanks! this is very helpful and works great.

      I am now stuck with trying to plot effects if I use splines for time
      So I create 4 splines for time as:

      mkspline time1 2 time2 10 time3 20 time4=time

      and then add time in my regression as
      xtreg y x##time1 x##time2 x##time3 x##time4

      however, I have yet to succeed at plotting trajectories over time by x when I use those time splines..
      If anyone has any suggestions on how to use margins or anything else to plot that, thanks!

      Comment


      • #4
        There is some advice here and here.

        Comment


        • #5
          Also [here](http://www.maartenbuis.nl/wp/inter_q...quadr_new.html)
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment

          Working...
          X