set more off
set linesize 150
global filesave "C:\Dropbox\PilesOfVariance\Chapter3a\STATA"
use "$filesave\STATA_Chapter3a.dta", clear
reshape long outcome, i(personid) j(time)
label variable time "time: Occasion (1=pre-test, 2=post-test)"
label variable outcome "outcome: Learning Outcome"
gen time1 = time - 1
gen treat = group - 1
label variable time1 "time1: Time (0=pre-test, 1=post-test)"
label variable treat "treat: Treatment Group (0=control, 1=treatment)"
log using $filesave\STATA_Chapter3a_Output, replace name(STATA_Chapter3a)
display as result "Chapter 3a Example: Means by group and time for learning outcome"
tabulate group time, summarize(outcome)
display as result "Eq 3a.1: Empty Between-Person Model"
mixed outcome ,
|| personid: , noconstant variance reml covariance(unstructured)
residuals(independent,t(time)),
estat ic, n(50),
estat wcorrelation, covariance,
estat wcorrelation,
display as result "Eq 3a.2: Empty Within-Person Model"
mixed outcome ,
|| personid: , noconstant variance reml covariance(unstructured)
residuals(exchangeable,t(time)),
estat ic, n(50),
estat wcorrelation, covariance,
estat wcorrelation,
display as result "Eq 3a.7: Conditional Between-Person Model (top of Eq. 3.7)"
display as result "Manual Contrasts for Time and Group"
mixed outcome c.time1 c.treat c.time1#c.treat,
|| personid: , noconstant variance reml covariance(unstructured)
residuals(independent,t(time)),
estat ic, n(50),
estat wcorrelation, covariance,
estat wcorrelation,
lincom _cons*1 + c.time1*0 + c.treat*0 + c.time1#c.treat*0
lincom _cons*1 + c.time1*1 + c.treat*0 + c.time1#c.treat*0
lincom _cons*1 + c.time1*0 + c.treat*1 + c.time1#c.treat*0
lincom _cons*1 + c.time1*1 + c.treat*1 + c.time1#c.treat*1
lincom c.time1*1 + c.time1#c.treat*0
lincom c.time1*1 + c.time1#c.treat*1
lincom c.treat*1 + c.time1#c.treat*0
lincom c.treat*1 + c.time1#c.treat*1
display as result "Eq 3a.7: Conditional Within-Person Model (bottom of Eq. 3.7)"
display as result "Manual Contrasts for Time and Group"
mixed outcome c.time1 c.treat c.time1#c.treat,
|| personid: , noconstant variance reml covariance(unstructured)
residuals(exchangeable,t(time)),
estat ic, n(50),
estat wcorrelation, covariance,
estat wcorrelation,
lincom _cons*1 + c.time1*0 + c.treat*0 + c.time1#c.treat*0
lincom _cons*1 + c.time1*1 + c.treat*0 + c.time1#c.treat*0
lincom _cons*1 + c.time1*0 + c.treat*1 + c.time1#c.treat*0
lincom _cons*1 + c.time1*1 + c.treat*1 + c.time1#c.treat*1
lincom c.time1*1 + c.time1#c.treat*0
lincom c.time1*1 + c.time1#c.treat*1
lincom c.treat*1 + c.time1#c.treat*0
lincom c.treat*1 + c.time1#c.treat*1
display as result "Eq 3a.7: Conditional Within-Person Model (bottom of Eq. 3.7)"
display as result "Categorical Predictors for Time and Group"
mixed outcome i.time1 i.treat i.time1#i.treat,
|| personid: , noconstant variance reml covariance(unstructured)
residuals(exchangeable,t(time)),
estat ic, n(50),
estat wcorrelation, covariance,
estat wcorrelation,
contrast i.time1#i.treat,
margins i.time1#i.treat,
margins i.time1#i.treat, pwcompare(pveffects)
margins i.time1@i.treat,
margins i.treat@i.time1,
log close STATA_Chapter3a
log2html $filesave\STATA_Chapter3a_Output, replace