set more off, permanently
set linesize 150
global filesave "C:\Dropbox\PilesOfVariance\Chapter11a\STATA"
use "$filesave\STATA_Chapter11a.dta", clear
egen smclose = rowmean(close_wave1 close_wave2 close_wave3)
egen smvictim = rowmean(victim_wave1 victim_wave2 victim_wave3)
label variable smclose "smclose: Student Mean Closeness"
label variable smvictim "smvictim: Student Mean Victimization"
egen cmclose = mean(smclose), by(classid)
egen cmvictim = mean(smvictim), by(classid)
egen cmgirl = mean(girl), by(classid)
label variable cmclose "cmclose: Class Mean Student-Teacher Closeness"
label variable cmvictim "cmvictim3: Class Mean Student-Perceived Victimization"
label variable cmgirl "cmgirl: Percentage Girls in Class"
egen cmemosup_wave1 = mean(emosup_wave1), by(classid)
egen cmemosup_wave2 = mean(emosup_wave2), by(classid)
egen cmemosup_wave3 = mean(emosup_wave3), by(classid)
egen cmemosup = rowmean(cmemosup_wave1 cmemosup_wave2 cmemosup_wave3)
drop cmemosup_wave1 cmemosup_wave2 cmemosup_wave3
label variable cmemosup "cmemosup: Class Mean Emotional Support"
gen size23 = classsize - 23
gen grade35=0
recode grade35 (0=1) if grade==5
gen cmgirl50 = cmgirl - .50
gen cmemosup5 = cmemosup - 5
gen cmvictim3 = cmvictim - 3
label variable size23 "size23: # Students in Class (0=23)"
label variable grade35 "grade35: Grade 3=0, Grade5=1"
label variable cmgirl50 "cmgirl50: Percentage Girls in Class (0=.50)"
label variable cmemosup5 "cmemosup5: Class Mean Emotional Support (0=5)"
label variable cmvictim3 "cmvictim3: Class Mean Student-Perceived Victimization (0=3)"
gen wcclose = smclose - cmclose
gen smvictim3 = smvictim - 3
gen wcvictim = smvictim - cmvictim
label variable wcclose "wcclose: Within-Class Student-Teacher Closeness (0=CM)"
label variable smvictim3 "smvictim3: Student Mean Student-Perceived Victimization (0=3)"
label variable wcvictim "wcvictim: Within-Class Student-Perceived Victimization (0=CM)"
reshape long emosup_wave victim_wave close_wave, i(studentid) j(wave)
gen emosup = emosup_wave
gen victim = victim_wave
gen close = close_wave
drop emosup_wave victim_wave close_wave
label variable wave "wave: Wave of Study (1-3)"
label variable emosup "emosup: Time-Varying Class Emotional Support"
label variable victim "victim: Time-Varying Student-Perceived Victimization"
label variable close "close: Time-Varying Student-Teacher Closeness"
sort classid studentid wave
gen time1 = wave - 1
gen time2 = wave - 2
gen w1=0
recode w1 (0=1) if wave==1
gen w2=0
recode w2 (0=1) if wave==2
gen w3=0
recode w3 (0=1) if wave==3
gen wsclose = close - smclose
gen victim3 = victim - 3
gen wsvictim = victim - smvictim
gen emosup5 = emosup - 5
gen wcemosup = emosup - cmemosup
label variable time1 "time1: Time in Study (0=Wave1)"
label variable time2 "time2: Time in Study (0=Wave2)"
label variable w3 "w3: Is Wave3 (0=no, 1=yes)"
label variable wsclose "wsclose: Within-Student Student-Teacher Closeness (0=SM)"
label variable victim3 "victim3: Time-Varying Student-Perceived Victimization (0=3)"
label variable wsvictim "wsvictim: Within-Student Student-Perceived Victimization (0=SM)"
label variable emosup5 "emosup5: Time-Varying Class Emotional Support (0=5)"
label variable wcemosup "wcemosup: Within-Class Emotional Support (0=CM)"
egen nummiss = rowmiss(wave victim emosup girl classsize close)
drop if nummiss>0
log using $filesave\STATA_Chapter11a_Output, replace name(STATA_Chapter11a)
display as result "Chapter 11a: Descriptive Statistics for Level-1 Time-Varying Student Variables"
summarize close wsclose victim wsvictim
display as result "Chapter 11a: Descriptive Statistics for Level-1 Time-Varying Class Variables"
preserve
collapse emosup wcemosup, by(classid wave)
summarize emosup wcemosup
restore
display as result "Chapter 11a: Descriptive Statistics for Level-2 Student Variables"
preserve
collapse smclose wcclose smvictim wcvictim girl, by(studentid)
summarize smclose wcclose smvictim wcvictim girl
restore
display as result "Chapter 11a: Descriptive Statistics for Level-3 Class Variables"
preserve
collapse cmclose cmvictim cmemosup cmgirl classsize grade35, by(classid)
summarize cmclose cmvictim cmemosup cmgirl classsize grade35
restore
display as result "Ch 11a: Empty Means, Two-Level Model Predicting Student-Teacher Closeness"
display as result "Occasions Within Students*Classes"
mixed close ,
|| classid: , noconstant variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
estimates store FitEmpty2C,
display as result "Eq 11a.1: Empty Means, Three-Level Model Predicting Student-Teacher Closeness"
display as result "Level-1 Occasions Within Level-2 Students Within Level-3 Classes"
mixed close ,
|| classid: , variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
estat icc,
estimates store FitEmpty3C,
lrtest FitEmpty3C FitEmpty2C,
display as result "Ch 11a: Empty Means, Two-Level Model Predicting Student-Perceived Victimization"
display as result "Occasions Within Students*Classes"
mixed victim ,
|| classid: , noconstant variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
estimates store FitEmpty2V,
display as result "Eq 11a.1: Empty Means, Three-Level Model Predicting Student-Perceived Victimization"
display as result "Level-1 Occasions Within Level-2 Students Within Level-3 Classes"
mixed victim ,
|| classid: , variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
estat icc,
estimates store FitEmpty3V,
lrtest FitEmpty3V FitEmpty2V,
display as result "Eq 11a.1: Empty Means, Levels 1 and 3 Model Predicting Class Emotional Support"
display as result "Level-1 Ocasions Within Level-3 Classes"
mixed emosup ,
|| classid: , variance reml covariance(unstructured),
estat ic, n(33),
estat icc,
estimates store FitEmpty3E,
display as result "Eq 11a.1: Empty Means, Levels 1 and 3 Model Predicting Class Emotional Support"
display as result "Level-1 Ocasions Within Level-3 Classes"
preserve
collapse emosup time1, by(classid wave)
mixed emosup ,
|| classid: , variance reml covariance(unstructured),
estat ic, n(33),
estat icc,
restore
display as result "Eq 11a.3: Saturated Means, Unstructured Level-3 and Level-2 Variances"
display as result "Predicting Student Closeness"
mixed close i.wave,
|| classid: w1 w2 w3, noconstant variance reml covariance(unstructured)
|| studentid: , noconstant covariance(unstructured)
residuals(unstructured,t(wave)),
estat ic, n(33),
estat recovariance, relevel(classid),
estat recovariance, relevel(classid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
contrast i.wave,
margins i.wave,
margins i.wave, pwcompare(pveffects)
estimates store FitSatUNC,
display as result "Ch 11a: Piecewise Means, Level-3 and Level-2 Random Intercepts"
display as result "Three-Level Model Predicting Student Closeness"
mixed close c.time1 c.w3,
|| classid: , variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
estimates store FitPieceRI2RI3C,
display as result "Ch 11a: Piecewise Means, Add Level-2 Random Time Slope"
display as result "Three-Level Model Predicting Student Closeness"
mixed close c.time1 c.w3,
|| classid: , variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitPieceRL2RI3C,
lrtest FitPieceRL2RI3C FitPieceRI2RI3C,
display as result "Ch 11a: Piecewise Means, Add Level-3 Random Time Slope"
display as result "Three-Level Model Predicting Student Closeness"
mixed close c.time1 c.w3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitPieceRL2RL3C,
lrtest FitPieceRL2RL3C FitPieceRL2RI3C, force
lrtest FitSatUNC FitPieceRL2RL3C, force
display as result "Eq 11a.4: Unconditional Growth Model Predicting Student Closeness"
display as result "Random Linear Time Slopes for Level-2 Students and Level-3 Classes"
mixed close c.time1,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
predict PredUncC, xb,
corr close PredUncC
display as result "Ch 11a: Add Class Grade and Class Size"
display as result "Predicting Student Closeness"
mixed close c.time1 c.grade35 c.time1#c.grade35 c.size23 c.time1#c.size23,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Class Size Only"
display as result "Predicting Student Closeness"
mixed close c.time1 c.size23 c.time1#c.size23,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Test if Level-3 Random Time Slope Variance is still needed"
display as result "Predicting Student Closeness"
mixed close c.time1 c.size23 c.time1#c.size23
c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50,
|| classid: , variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Saturated Means, Unstructured Model Predicting Class Emotional Support"
display as result "Using Only Level-1 Ocasions Within Level-3 Classes"
preserve
collapse emosup time1, by(classid wave)
mixed emosup i.wave,
|| classid: , noconstant variance reml covariance(unstructured)
residuals(unstructured,t(wave)),
estat ic, n(33),
estat wcorrelation, covariance,
estat wcorrelation,
contrast i.wave,
margins i.wave,
margins i.wave, pwcompare(pveffects)
estimates store FitSatUNE,
restore
display as result "Ch 11a: Saturated Means, Random Intercept Model Predicting Class Emotional Support"
display as result "Using Only Level-1 Ocasions Within Level-3 Classes"
preserve
collapse emosup time1, by(classid wave)
mixed emosup i.wave,
|| classid: , variance reml covariance(unstructured),
estat ic, n(33),
estimates store FitSatRIE,
lrtest FitSatUNE FitSatRIE, force
restore
display as result "Ch 11a: Saturated Means, Random Time Slope Model Predicting Class Emotional Support"
display as result "Using Only Level-1 Ocasions Within Level-3 Classes"
preserve
collapse emosup time1, by(classid wave)
mixed emosup i.wave,
|| classid: time1, variance reml covariance(unstructured),
estat ic, n(33),
restore
display as result "Eq 11a.6: Add Time-Varying and Class Emotional Support"
display as result "Predicting Student Closeness"
mixed close c.time1 c.size23 c.time1#c.size23
c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.emosup5 c.time1#c.emosup5 c.cmemosup5 c.time1#c.cmemosup5,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
test (c.emosup5=0) (c.time1#c.cmemosup5=0)
test (c.cmemosup5=0) (c.time1#c.cmemosup5=0)
estimates store FitEmosup13C,
display as result "Ch 11a: New Baseline for Pseudo-R2 without Class Size Effects"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Just Level-3 Emotional Support Effects"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
test (c.cmemosup5=0) (c.time1#c.cmemosup5=0)
lincom c.cmemosup5*1 + c.cmemosup5#c.time1*0
lincom c.cmemosup5*1 + c.cmemosup5#c.time1*1
lincom c.cmemosup5*1 + c.cmemosup5#c.time1*2
estimates store FitEmosup3C,
display as result "Ch 11a: Piecewise Means, Level-3 and Level-2 Random Intercepts"
display as result "Three-Level Model Predicting Student Victimization"
mixed victim c.time1 c.w3,
|| classid: , variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
estimates store FitPieceRI2RI3V,
display as result "Ch 11a: Piecewise Means, Add Level-2 Random Time Slope"
display as result "Three-Level Model Predicting Student Victimization"
mixed victim c.time1 c.w3,
|| classid: , variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitPieceRL2RI3V,
lrtest FitPieceRL2RI3V FitPieceRI2RI3V,
display as result "Ch 11a: Piecewise Means, Add Level-3 Random Time Slope"
display as result "Three-Level Model Predicting Student Victimization"
mixed victim c.time1 c.w3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitPieceRL2RL3V,
lrtest FitPieceRL2RL3V FitPieceRL2RI3V
display as result "Ch 11a: Fixed Linear Time, Level-3 and Level-2 Random Intercepts"
display as result "Three-Level Model Predicting Student Victimization"
mixed victim c.time1,
|| classid: , variance reml covariance(unstructured)
|| studentid: , covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add All 3 Main Effects of Student Vicitimization Predicting Student Closeness"
display as result "Using Variable-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.wsvictim c.wcvictim c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
lincom c.wsvictim*1
lincom c.wcvictim*1
lincom c.cmvictim3*1
lincom c.wsvictim*-1 + c.wcvictim*1
lincom c.wcvictim*-1 + c.cmvictim3*1
estimates store FitVicVBC,
display as result "Ch 11a: Add All 3 Main Effects of Student Vicitimization Predicting Student Closeness"
display as result "Using Constant-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.victim3 c.smvictim3 c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
lincom c.victim3*1
lincom c.victim3*1 + c.smvictim3*1
lincom c.victim3*1 + c.smvictim3*1 + c.cmvictim3*1
lincom c.smvictim3*1
lincom c.cmvictim3*1
display as result "Ch 11a: Constant-Centered Student Vicitimization Predicting Student Closeness"
display as result "For Table 11.3: Level-2 and Level-3 Effects, Omitting Level-1 Effect"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.smvictim3 c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Constant-Centered Student Vicitimization Predicting Student Closeness"
display as result "For Table 11.3: Level-1 and Level-3 Effects Only, Omitting Level-2 Effect"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.victim3 c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Constant-Centered Student Vicitimization Predicting Student Closeness"
display as result "For Table 11.3: Level-1 and Level-2 Effects, Omitting Level-3 Effect"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.victim3 c.smvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Constant-Centered Student Vicitimization Predicting Student Closeness"
display as result "For Table 11.3: Level-1 Effect Only, Omitting Level-2 and Level-3 Effects"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.victim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add All 3 Victim*Time Interactions Predicting Student Closeness"
display as result "Using Variable-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.wsvictim c.wcvictim c.cmvictim3
c.time1#c.wsvictim c.time1#c.wcvictim c.time1#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add All 3 Victim*Time Interactions Predicting Student Closeness"
display as result "Using Constant-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.victim3 c.smvictim3 c.cmvictim3
c.time1#c.victim3 c.time1#c.smvictim3 c.time1#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Random Within-Student Vicitimization Effect across Students"
display as result "Using Variable-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.wsvictim c.wcvictim c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
estimates store FitVicRWS2C,
lrtest FitVicRWS2C FitVicVBC,
display as result "Ch 11a: Add Quadratic Level-3 Effects of Gender"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmgirl50 c.time1#c.cmgirl50#c.cmgirl50,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Quadratic Level-3 Effects of Emotional Support"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmemosup5#c.cmemosup5 c.time1#c.cmemosup5#c.cmemosup5,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Quadratic Effect of Victimization at Each Level"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmvictim3#c.cmvictim3 c.wcvictim#c.wcvictim c.wsvictim#c.wsvictim,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Two-Way and Three-Way Interactions Among Level-3 Effects"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmgirl50#c.cmvictim3 c.cmemosup5#c.cmvictim3
c.time1#c.cmgirl50#c.cmemosup5 c.time1#c.cmgirl50#c.cmvictim3 c.time1#c.cmemosup5#c.cmvictim3
c.cmgirl50#c.cmemosup5#c.cmvictim3 c.time1#c.cmgirl50#c.cmemosup5#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Keep Gender*Emotional Support and Emotional Support*Victimization Level-3 Interactions"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Time by Level-2 Interactions (and Contextual Level-3 Interactions)"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim
c.time1#c.wcvictim c.time1#c.girl#c.wcvictim c.time1#c.cmvictim3 c.time1#c.cmgirl50#c.wcvictim,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Level-3 by Within-Class Victim Cross-Level Interactions"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim
c.wcvictim#c.cmemosup5 c.wcvictim#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Level-3 by Within-Student Victim Cross-Level Interactions"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim
c.wsvictim#c.cmgirl50 c.wsvictim#c.cmemosup5 c.wsvictim#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Eq 11a.9: Add Level-2 and Level-3 Victim by Within-Student Victim Cross-Level Interactions"
display as result "Final Model Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim
c.wsvictim#c.wcvictim c.wsvictim#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
lincom c.cmgirl50*1 + c.cmgirl50#c.time1*0
lincom c.cmgirl50*1 + c.cmgirl50#c.time1*1
lincom c.cmgirl50*1 + c.cmgirl50#c.time1*2
lincom c.cmemosup5*1 + c.cmemosup5#c.time1*0
lincom c.cmemosup5*1 + c.cmemosup5#c.time1*1
lincom c.cmemosup5*1 + c.cmemosup5#c.time1*2
lincom c.wcvictim*1 + c.wcvictim#c.girl*1
predict FinalC, xb,
corr close FinalC
display as result "Ch 11a: Add Level-2 and Level-3 Gender by Within-Student Victim Cross-Level Interactions"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim c.wsvictim#c.wcvictim c.wsvictim#c.cmvictim3
c.wsvictim#c.girl c.wsvictim#c.cmgirl50,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Eq 11a.9: Add Level-2 and Level-3 Victim by Within-Student Victim Cross-Level Interactions"
display as result "Predicting Student Closeness using ML instead of REML"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim
c.wsvictim#c.wcvictim c.wsvictim#c.cmvictim3,
|| classid: time1, variance mle covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
log close STATA_Chapter11a
log2html $filesave\STATA_Chapter11a_Output, replace
display as result "Eq 11a.5: Add Student and Class Gender"
display as result "Predicting Student Closeness"
mixed close c.time1 c.size23 c.time1#c.size23
c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
test (c.girl=0) (c.time1#c.girl=0)
test (c.cmgirl50=0) (c.time1#c.cmgirl50=0)
lincom c.cmgirl50*1 + c.cmgirl50#c.time1*0
lincom c.cmgirl50*1 + c.cmgirl50#c.time1*1
lincom c.cmgirl50*1 + c.cmgirl50#c.time1*2
estimates store FitGirlC,
display as result "Ch 11a: Add Random Gender Effect across Classes"
display as result "Predicting Student Closeness"
mixed close c.time1 c.size23 c.time1#c.size23
c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50,
|| classid: time1 girl, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitRandGirlC,
lrtest FitRandGirlC FitGirlC, force
display as result "Ch 11a: Remove Class Size, Add Random Level-1 Emotional Support across Classes"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.emosup5 c.time1#c.emosup5 c.cmemosup5 c.time1#c.cmemosup5,
|| classid: time1 emosup5, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitEmosup13RC,
display as result "Eq 11a.3: Saturated Means, Unstructured Level-3 and Level-2 Variances"
display as result "for Student Victimization"
mixed victim i.wave,
|| classid: w1 w2 w3, noconstant variance reml covariance(unstructured)
|| studentid: , noconstant covariance(unstructured)
residuals(unstructured,t(wave)),
estat ic, n(33),
estat recovariance, relevel(classid),
estat recovariance, relevel(classid) correlation,
estat wcorrelation, covariance,
estat wcorrelation,
contrast i.wave,
margins i.wave,
margins i.wave, pwcompare(pveffects)
estimates store FitSatUNV,
display as result "Ch 11a: Add Random Within-Class Vicitimization Effect across Classes"
display as result "Using Variable-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.wsvictim c.wcvictim c.cmvictim3,
|| classid: time1 wcvictim, variance reml covariance(unstructured)
|| studentid: time1, covariance(unstructured),
estat ic, n(33),
estimates store FitVicRWC3C,
lrtest FitVicRWC3C FitVicVBC,
display as result "Ch 11a: Add Random Within-Student Vicitimization Effect across Classes"
display as result "Using Variable-Centered Level-1 and Level-2 Victim Predictors"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5
c.wsvictim c.wcvictim c.cmvictim3,
|| classid: time1 wcvictim, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
estimates store FitVicRWS23C,
lrtest FitVicRWS23C FitVicRWS2C,
display as result "Eq 11a.8: Add Level-2 Interactions (and Contextual Level-3 Interactions)"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),
display as result "Ch 11a: Add Level-3 by Student Gender Cross-Level Interactions"
display as result "Predicting Student Closeness"
mixed close c.time1 c.girl c.time1#c.girl c.cmgirl50 c.time1#c.cmgirl50
c.cmemosup5 c.time1#c.cmemosup5 c.wsvictim c.wcvictim c.cmvictim3
c.cmgirl50#c.cmemosup5 c.cmemosup5#c.cmvictim3
c.girl#c.wcvictim c.cmgirl50#c.wcvictim
c.girl#c.cmgirl50 c.girl#c.cmemosup5 c.girl#c.cmvictim3,
|| classid: time1, variance reml covariance(unstructured)
|| studentid: time1 wsvictim, covariance(unstructured),
estat ic, n(33),