infile obs id age dist sex using "C:\Documents and Settings\Yijie\My Documents\ldata\dental.dat" ** save as .dta if you like; drop obs summ ** make in wide format, and save; reshape wide dist, i(id) j(age) reshape long dist, i(id) j(age) ** convert an ordinary data into a longitudinal dataset, specifying subject index and time index; tsset id age ** Brief review on the LDA commands ** ; *********************************************; ** xtdes Describe pattern of xt data; ** xtsum Summarize xt data; ** xttab Tabulate xt data; ** xtdata Faster specification searches with xt data; ** xtreg Fixed-, between- and random-effects, and population-averaged linear models; ** xtregar Fixed- and random-effects linear models with an AR(1) disturbance; ** xtlogit Fixed-effects, random-effects, & population-averaged logit models; ** xtpois Fixed-effects, random-effects, & population-averaged Poisson models; ** xtgee Population-averaged panel-data models using GEE; ********************************************************************; ** EDA analysis -- distance difference across boys and girls over time ** ; ** describe the pattern of data, including the missing pattern; xtdes sort age by age: sum dist graph dist, by(age) box ** in STATA 8, please do " graph box dist, by(age) ";** ** the time-varying variables are: age, dist; ** the baseline variables are: id, sex; ** to summarize: means, standard deviations, frequenct, for time-series (xt) data; xttab sex ** Mean trend plot***; xtgraph dist, group(sex) ti("Mean distance vs age") bar(se) ** Spaghetti plots ** sort sex id age graph dist age, by(sex) c(L) s(i) ** in STATA 8, please do "twoway line dist age, by(sex) c(l) s(i)"; ** ** kernel smooth ** ksm dist age, lowess gen(distsmth) nograph graph dist distsmth age, c(.L.) s(.i.) ** in STATA 8, please do "twoway (scatter dist age) (connected distsmth age) "; ** gen distm = dist if sex == 0 gen distf = dist if sex == 1 ksm distm age, lowess gen(distmsmth) graph dist distmsmth age, c(.L.) s(.io) ** in STATA 8, please do "twoway (scatter dist age) (connected distmsmth age) "; ** ksm distf age, lowess gen(distfsmth) graph dist distfsmth age, c(.L.) s(.io) ** in STATA 8, please do "twoway (scatter dist age) (connected distfsmth age) "; ** ** explore the within- and between subject variability **; ** For now, disregard the sex effect here; ** without adjusting age effects (time trend); xtsumcorr dist ** The within-panel standard deviation is the same as that in{cmd:xtsum}, ** except that the divisor of the variance is (N - n) instead of (N - 1), ** where N is the total sample size and n is the number of subjects. ** The between-panel standard deviation is computed as the square root of the overall variance minus the within-panel variance. ** adjusting age effects (time trend); ** we need to use residual of Y after adjusting for age and sex effect; xi: reg dist i.age sex predict distres1, resid xtsumcorr distres1 ** last, to explore the correlation structure of response ***; ** first, to remove the effects of covariates, including age categories, sex; ** to calculate the autocorelation function, and plots **; autocor distres1 age id variogram distres1