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