set more off
set linesize 150
global filesave "C:\Dropbox\PilesOfVariance\Chapter7a\STATA"
use "$filesave\STATA_Chapter7a.dta", clear
gen studyday1 = studyday - 1
gen dayofweek1 = dayofweek - 1
gen age80 = baseage - 80
label variable studyday1 "studyday1: Day of Study (0=1)"
label variable dayofweek1 "dayofweek1: Day of Week (0=1)"
label variable age80 "age80: Baseline Age (0=80)"
egen nummiss = rowmiss(women baseage symptoms mood stressor mood)
drop if nummiss>0
drop if studyday>14
log using $filesave\STATA_Chapter7a_Output, replace name(STATA_Chapter7a)
display as result "Chapter 7a: Descriptive Statistics for Time-Invariant Variables"
preserve
collapse women baseage, by(personid)
summarize women baseage
restore
display as result "Chapter 7a: Descriptive Statistics for Time-Varying Variables"
summarize symptoms
display as result "Eq 7a.3: Empty Means, Random Intercept Model"
mixed symptoms ,
|| personid: , variance mle covariance(unstructured),
estat ic, n(105),
estat icc,
estat wcorrelation, covariance,
estat wcorrelation,
estimates store FitEmpty,
display as result "Ch 7a: Testing Saturated Means by Day of Study"
display as result "Random Intercept Only"
mixed symptoms i.studyday,
|| personid: , variance mle covariance(unstructured),
estat ic, n(105),
contrast i.studyday,
margins i.studyday,
margins i.studyday, pwcompare(pveffects)
display as result "Ch 7a: Testing Fixed Linear Effect of Day of Study"
display as result "Random Intercept Only"
mixed symptoms c.studyday1,
|| personid: , variance mle covariance(unstructured),
estat ic, n(105),
estimates store FitFixDayofStudy,
display as result "Ch 7a: Testing Random Linear Effect of Day of Study"
mixed symptoms c.studyday1,
|| personid: studyday1, variance mle covariance(unstructured),
estat ic, n(105),
estimates store FitRandDayofStudy,
lrtest FitRandDayofStudy FitFixDayofStudy,
display as result "Ch 7a: Testing Saturated Means by Day of Week"
display as result "Random Intercept Only"
mixed symptoms i.dayofweek,
|| personid: , variance mle covariance(unstructured),
estat ic, n(105),
contrast i.dayofweek,
margins i.dayofweek,
margins i.dayofweek, pwcompare(pveffects)
display as result "Ch 7a: Testing Fixed Effect of Weekend"
display as result "Random Intercept Only"
mixed symptoms c.weekend,
|| personid: , variance mle covariance(unstructured),
estat ic, n(105),
estimates store FitFixWeekend,
display as result "Ch 7a: Testing Random Effect of Weekend"
mixed symptoms c.weekend,
|| personid: weekend, variance mle covariance(unstructured),
estat ic, n(105),
estimates store FitRandWeekend,
lrtest FitRandWeekend FitFixWeekend,
display as result "Eq 7a.4: Adding Sex and Age to the Model for the Means"
mixed symptoms c.women c.age80 c.women#c.age80,
|| personid: , variance mle covariance(unstructured),
estat ic, n(105),
estat vce,
test (c.women=0) (c.age80=0) (c.women#c.age80=0)
lincom c.age80*1 + c.women#c.age80*0
lincom c.age80*1 + c.women#c.age80*1
estimates store FitSexAge,
lrtest FitSexAge FitEmpty,
predict PredSexAge, xb,
corr symptoms PredSexAge
log close STATA_Chapter7a
log2html $filesave\STATA_Chapter7a_Output, replace