set more off
set linesize 150
global filesave "C:\Dropbox\PilesOfVariance\Chapter5\STATA"
use "$filesave\STATA_Chapter5.dta", clear
gen time = wave - 1
label variable time "time: Time in Study (0=1)"
log using $filesave\STATA_Chapter5_Output, replace name(STATA_Chapter5)
display as result "Chapter 5 Example: Means by Wave for outcome"
tabulate wave, summarize(outcome)
display as result "Eq 5.1: Empty Means, Random Intercept Model"
mixed outcome ,
|| personid: , variance reml covariance(unstructured)
residuals(independent,t(wave)),
estat ic, n(25),
estat icc,
estat recovariance, relevel(personid),
estat recovariance, relevel(personid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
display as result "Eq 5.3: Fixed Linear Time, Random Intercept Model"
mixed outcome c.time,
|| personid: , variance reml covariance(unstructured)
residuals(independent,t(wave)),
estat ic, n(25),
estat recovariance, relevel(personid),
estat recovariance, relevel(personid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
lincom _cons*1 + c.time*0
lincom _cons*1 + c.time*1
lincom _cons*1 + c.time*2
lincom _cons*1 + c.time*3
estimates store FitFixLin,
display as result "Eq 5.5: Random Linear Time Model"
mixed outcome c.time,
|| personid: time, variance reml covariance(unstructured)
residuals(independent,t(wave)),
estat ic, n(25),
estat recovariance, relevel(personid),
estat recovariance, relevel(personid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
lincom _cons*1 + c.time*0
lincom _cons*1 + c.time*1
lincom _cons*1 + c.time*2
lincom _cons*1 + c.time*3
estimates store FitRandLin,
lrtest FitRandLin FitFixLin,
display as result "Ch 5: Saturated Means, Unstructured Variance Model"
display as result "ANSWER KEY for both sides of the model"
mixed outcome i.wave,
|| personid: , noconstant variance reml covariance(unstructured)
residuals(unstructured,t(wave)),
estat ic, n(25),
estat wcorrelation, covariance,
estat wcorrelation,
contrast i.wave,
margins i.wave,
margins i.wave, pwcompare(pveffects)
display as result "Ch 5: Random Linear Time Model with AR1 R Matrix"
mixed outcome c.time,
|| personid: time, variance reml covariance(unstructured)
residuals(ar1,t(wave)),
estat ic, n(25),
estat recovariance, relevel(personid),
estat recovariance, relevel(personid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
estimates store FitRandLinAR1,
lrtest FitRandLinAR1 FitRandLin,
display as result "Ch 5: Random Linear Time Model with TOEP2 R Matrix"
mixed outcome c.time,
|| personid: time, variance reml covariance(unstructured)
residuals(toeplitz1,t(wave)),
estat ic, n(25),
estat recovariance, relevel(personid),
estat recovariance, relevel(personid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
estimates store FitRandLinTOEP2,
lrtest FitRandLinTOEP2 FitRandLin,
log close STATA_Chapter5
log2html $filesave\STATA_Chapter5_Output, replace