set memory 40m set matsize 100 ** read in the data set ** reshape long week, i(Id) j(time) tsset Id time xtdes sort time graph week, by(time) box ** STATA 8 command : graph box week, by(time) ** ** mean trend plot ** xtgraph week, ti("Mean trend vs time") bar(se) ** scatter matrix plot ** reshape wide week, i(Id) j(time) graph week1 week2 week3 week4 week5 week6 week7 week8 week9, matrix half ** spaghetti plot ** reshape long week, i(Id) j(time) sort Id time graph week time, c(L) s(i) ** STATA 8 command : twoway line week time, c(L) s(i) ** ** standardize, and spaghetti plot ** sort time by time: sum week reshape wide week, i(Id) j(time) gen sweek1 = (week1 - 25.02)/2.47 gen sweek2 = (week2 - 31.78)/2.79 gen sweek3 = (week3 - 38.86)/3.54 gen sweek4 = (week4 - 44.39)/3.73 gen sweek5 = (week5 - 50.16)/4.53 gen sweek6 = (week6 - 56.45)/4.45 gen sweek7 = (week7 - 62.46)/4.97 gen sweek8 = (week8 - 69.30)/5.42 gen sweek9 = (week9 - 75.22)/6.34 reshape long week sweek, i(Id) j(time) sort Id time graph sweek time, c(L) s(i) ** STATA 8 command : twoway line sweek time, c(L) s(i) ** ** explore correlation structure ** autocor week time Id ** residual correlation structure ** regress week time predict weekrs, resid autocor weekrs time Id variogram weekrs ** ordinary least square (OLS)** regress week time ** indep corr, to compare with OLS ** xtgee week time, i(Id) corr(ind) xtcorr xtgls week time, i(Id) corr(ind) ** uniform corr ** xtgee week time, i(Id) corr(exc) xtcorr ** equivalent command ** xtreg week time, i(Id) pa ** random intercept, to compare with uniform corr ** xtreg week time, re i(Id) ** random intercept mle ** xtreg week time, i(Id) mle ** exponential corr ** xtgls week time, igls corr(ar1) i(Id) force xtgee week time, i(Id) corr(ar1) t(time)