I've seen this problem a couple of times when I try to make a spaghetti plot (series for every individual). When I run the code below, the graph ends up with back-and-forth trajectories as if people are traveling backwards in time. I also tried SORT, but it does not seem to help. Any help or advice would be most appreciated! data long;
call streaminit(1234);
do p = 1 to 50; * persons;
* personal intercept;
int = 10 + 2 * rand("Normal");
* personal slope;
slo = 1 + rand("Normal");
* treatment dummy;
if p LT 25 then trt = 0;
else trt = 1;
* time loop;
do t = 1 to 6;
*regression model;
Y = int + (t-1) * slo /* basic growth */
+ .2 * trt * (t-1)**2 /* treatment effect */
+ 1.5 * rand("Normal"); /* time-specific error*/
output;
end;
end;
run;
proc sort data=long; by p t; run;
* spaghetti plot;
proc sgplot data=long noautolegend;
series Y = Y X = t / group = p lineattrs=(color=ligr pattern=1);
reg Y = Y X = t / group = trt nomarkers;
run; The result shows trajectories going back and forth in time (X).
... View more