Announcement

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

  • Graphing interactions using mixed

    Dear Statalist users,


    I'm trying to graph some age and cohort interactions from some results generated with mixed to illustrate cohort changes in attitudes over age:

    Code:
    mixed cdw i.cohortnew2##c.agecohortnew2 || pid: agecohortnew2, cov (un) reml variance
    Here is the data:

    Code:
    * Example generated by -dataex-. To install:    ssc    install    dataex
    clear
    input float(cdw cohortnew2 agecohortnew2)
    3 1  4
    1 1  0
    3 1  2
    3 1  4
    1 1  0
    6 1 -4
    2 1 -5
    5 1 -2
    2 1 -5
    4 1  0
    1 1  3
    4 1 -4
    1 1  0
    7 1 -1
    2 1 -1
    1 1 -1
    2 1 -2
    4 1 -3
    3 1 -3
    2 1 -4
    1 1 -1
    3 1 -1
    3 1  0
    4 1  1
    1 1  0
    1 1  2
    2 1  0
    2 1 -3
    2 1 -3
    1 1 -1
    2 1 -5
    3 1 -3
    1 1  2
    3 1 -3
    3 1  4
    1 1 -1
    1 1 -5
    2 1 -1
    1 1 -1
    5 1  0
    4 1 -1
    1 1  0
    1 1 -2
    1 1 -2
    2 1 -3
    7 1 -5
    2 1 -2
    4 1  3
    7 1 -5
    1 1  0
    6 1  3
    5 1  2
    6 1  2
    4 1  2
    4 1  2
    4 1  4
    4 1 -5
    1 1 -1
    5 1 -5
    2 1 -2
    1 1  3
    1 1 -4
    3 1 -5
    2 1 -4
    1 1  0
    3 1 -5
    3 1  3
    2 1 -3
    1 1  0
    1 1 -4
    1 1 -1
    1 1  3
    1 1 -5
    1 1 -1
    1 1  0
    7 1  0
    1 1 -2
    1 1  2
    1 1 -3
    1 1  4
    5 1 -4
    1 1 -5
    6 1 -1
    2 1 -3
    3 1 -2
    5 1  0
    3 1 -4
    3 1 -3
    4 1 -3
    3 1  1
    3 1 -1
    3 1  0
    1 1  2
    3 1 -4
    2 1 -5
    1 1 -4
    4 1  0
    2 1 -5
    4 1  0
    1 1 -4
    end
    To do this, I know I should use margins followed by marginsplot, but how do I do it so that I just get the cohort effects for the ages in which they're observed and not cohort effects across the entire age range - e.g. the latest-born cohort includes those born between 1985and 2000 and the data range is 2001 to 2017 so I shouldn't be able to see predicted marginal effects for this cohort at 90 cause they're not 90 yet. Does this make sense?

    Any help would be greatly appreciated

  • #2
    Hi Brendan. The first thought that came to mind for me is that it might be easier to use -predict- and -twoway- to generate your plot, as this will ensure that only actual data points are plotted. My second thought was that maybe you could include the addplot() option on -marginsplot- to overlay the actual data points. That would also make it clear where there are data points, and where you are extrapolating into no man's land. HTH.


    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment

    Working...
    X