* Prevent "more" messages from appearing set more off * Control line length set linesize 150 ******************************************************************************** ******* BEGIN DATA MANIPULATION FOR CHAPTER 8 EXAMPLE ******* ******* CHANGE "filesave" to your directory ******* ******************************************************************************** * Defining global variable for file location to be replaced in code below global filesave "C:\Dropbox\PilesOfVariance\Chapter8\STATA" * Import chapter 8 stacked data and create person means within it use "$filesave\STATA_Chapter8.dta", clear egen pmmood = mean(mood), by(personid) egen pmstressor = mean(stressor), by(personid) label variable pmstressor "pmstressor: Person Mean Stressors" label variable pmmood "pmmood: Person Mean Negative Mood" * Create centered predictors for analysis gen age80 = baseage - 80 gen mood2 = mood - 2 gen wpmood = mood - pmmood gen pmmood2 = pmmood - 2 gen wpstressor = stressor - pmstressor gen pmstressor40 = pmstressor - .40 label variable age80 "age80: Baseline Age (0=80)" label variable mood2 "mood2: Daily Negative Mood (0=2)" label variable wpmood "wpmood: Within-Person Negative Mood (0=PM)" label variable pmmood2 "pmmood2: Person Mean Negative Mood (0=2)" label variable wpstressor "wpstressor: Within-Person Stressors (0=PM)" label variable pmstressor40 "pmstressor40: Mean #Days with Stressor (0=0.40)" * Subset sample to complete cases for all predictors egen nummiss = rowmiss(women baseage symptoms mood stressor mood) drop if nummiss>0 * Subset sample to study days within a two-week period drop if studyday>14 ******************************************************************************** ******* BEGIN CHAPTER 8 MODELS ******* ******* NOTE: HETEROGENEOUS VARIANCE MODELS ARE NOT POSSIBLE IN STATA ******* ******************************************************************************** * Save results to separate file log using $filesave\STATA_Chapter8_Output, replace name(STATA_Chapter8) display as result "Chapter 8: Descriptive Statistics for Time-Invariant Variables" preserve collapse women baseage mood stressor, by(personid) summarize women baseage mood stressor restore display as result "Chapter 8: Descriptive Statistics for Time-Varying Variables" summarize symptoms mood stressor wpmood wpstressor display as result "Eq 8.1: Conditional Baseline Model" display as result "Just Sex and Age in the Model for the Means" mixed symptoms c.women c.age80 c.women#c.age80, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), estimates store FitSexAge, predict PredSexAge, xb, display as result "Ch 8: Empty Means, Random Intercept Model for Negative Mood Predictor" mixed mood , /// || personid: , variance mle covariance(unstructured), estat ic, n(105), estat icc, estat wcorrelation, covariance, estat wcorrelation, display as result "Eq 8.3: Adding BP and WP Effects of Negative Mood to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Multivariate Test of BP and WP Negative Mood Fixed Effects test (c.pmmood2=0) (c.wpmood=0) * Age Slope for Men lincom c.age80*1 + c.women#c.age80*0 * Age Slope for Women lincom c.age80*1 + c.women#c.age80*1 * Contextual Negative Mood Effect lincom c.wpmood*-1 + c.pmmood2*1 * Predicted Symptoms for PMmood=2 WPmood=-1 lincom _cons*1 + c.pmmood2*0 + c.wpmood*-1 * Predicted Symptoms for PMmood=2 WPmood=0 lincom _cons*1 + c.pmmood2*0 + c.wpmood*0 * Predicted Symptoms for PMmood=2 WPmood=1 lincom _cons*1 + c.pmmood2*0 + c.wpmood*1 * Predicted Symptoms for PMmood=3 WPmood=-1 lincom _cons*1 + c.pmmood2*1 + c.wpmood*-1 * Predicted Symptoms for PMmood=3 WPmood=0 lincom _cons*1 + c.pmmood2*1 + c.wpmood*0 * Predicted Symptoms for PMmood=3 WPmood=1 lincom _cons*1 + c.pmmood2*1 + c.wpmood*1 * Predicted Symptoms for PMmood=1 WPmood=0 lincom _cons*1 + c.pmmood2*-1 + c.wpmood*0 * Predicted Symptoms for PMmood=2 WPmood=0 lincom _cons*1 + c.pmmood2*0 + c.wpmood*0 * Predicted Symptoms for PMmood=3 WPmood=0 lincom _cons*1 + c.pmmood2*1 + c.wpmood*0 * Predicted Symptoms for PMmood=4 WPmood=0 lincom _cons*1 + c.pmmood2*2 + c.wpmood*0 estimates store FitBPWPMood, lrtest FitBPWPMood FitSexAge, predict PredBPWPMood, xb, corr symptoms PredBPWPMood display as result "Eq 8.5: Adding Smushed Effect of Negative Mood to the Model for the Means" display as result "Using Grand-Mean-Centering for Negative Mood" mixed symptoms c.women c.age80 c.women#c.age80 /// c.mood2, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Age Slope for Men lincom c.age80*1 + c.women#c.age80*0 * Age Slope for Women lincom c.age80*1 + c.women#c.age80*1 display as result "Eq 8.7: Adding a Contextual Effect of Negative Mood to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood" mixed symptoms c.women c.age80 c.women#c.age80 /// c.mood2 c.pmmood2, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Age Slope for Men lincom c.age80*1 + c.women#c.age80*0 * Age Slope for Women lincom c.age80*1 + c.women#c.age80*1 * Between-Person Negative Mood Effect lincom c.mood2*1 + c.pmmood2*1 estimates store FitBPWPMood, predict PredBPWPMood2, xb, corr symptoms PredBPWPMood2 display as result "Eq 8.9: Adding a Random Effect of Negative Mood to the Model for the Variance" display as result "Using Person-Mean-Centering for Negative Mood" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood, /// || personid: wpmood, variance mle covariance(unstructured), estat ic, n(105), estat recovariance, relevel(personid), estat recovariance, relevel(personid) correlation, estimates store FitRandPMC, lrtest FitRandPMC FitBPWPMood, display as result "Eq 8.9: Adding a Random Effect of Negative Mood to the Model for the Variance" display as result "Using Grand-Mean-Centering for Negative Mood" mixed symptoms c.women c.age80 c.women#c.age80 /// c.mood2 c.pmmood2, /// || personid: mood2, variance mle covariance(unstructured), estat ic, n(105), estat recovariance, relevel(personid), estat recovariance, relevel(personid) correlation, estimates store FitRandGMC, lrtest FitRandGMC FitBPWPMood, display as result "Eq 8.10: Adding Contextual and WP Effects of Stressors to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Multivariate Test of Stressor Fixed Effects test (c.pmstressor40=0) (c.stressor=0) * Intercept for Women lincom _cons*1 + c.women*1 * Age Slope for Women lincom c.age80*1 + c.women#c.age80*1 * Contextual Negative Mood Effect lincom c.wpmood*-1 + c.pmmood2*1 * Between-Person Stressor Effect lincom c.stressor*1 + c.pmstressor40*1 * Contextual Negative Mood Effect Per Day lincom c.pmmood2*.2 estimates store FitBPWPStressor, lrtest FitBPWPStressor FitBPWPMood, lrtest FitBPWPStressor FitSexAge, predict PredBPWPStressor, xb, corr symptoms PredBPWPStressor display as result "Ch 8: Adding Random WP Effect of Stressors to the Model for the Variance" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor, /// || personid: stressor, variance mle covariance(unstructured), estat ic, n(105), estat recovariance, relevel(personid), estat recovariance, relevel(personid) correlation, estimates store FitBPWPStressorR, lrtest FitBPWPStressorR FitBPWPStressor, display as result "Eq 8.11: Adding 4 Sex*Negative Mood and Sex*Stressors Interactions to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor /// c.women#c.pmmood2 c.women#c.wpmood c.women#c.pmstressor40 c.women#c.stressor, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Multivariate Test of 4 Sex Interactions test (c.women#c.pmmood2=0) (c.women#c.wpmood=0) (c.women#c.pmstressor40=0) (c.women#c.stressor=0) * Intercept: Men lincom _cons*1 + c.women*0 * Intercept: Women lincom _cons*1 + c.women*1 * Intercept: Sex Diff lincom c.women*1 * Age Slope: Men lincom c.age80*1 + c.women#c.age80*0 * Age Slope: Women lincom c.age80*1 + c.women#c.age80*1 * Age Slope: Sex Diff lincom c.women#c.age80*1 * BP Negative Mood: Men lincom c.pmmood2*1 + c.women#c.pmmood2*0 * BP Negative Mood: Women lincom c.pmmood2*1 + c.women#c.pmmood2*1 * BP Negative Mood: Sex Diff lincom c.women#c.pmmood2*1 * Contextual Negative Mood: Men lincom c.wpmood*-1 + c.women#c.wpmood *0 + c.pmmood2*1 + c.women#c.pmmood2*0 * Contextual Negative Mood: Women lincom c.wpmood*-1 + c.women#c.wpmood*-1 + c.pmmood2*1 + c.women#c.pmmood2*1 * Contextual Negative Mood: Sex Diff lincom c.women#c.wpmood*-1 + c.women#c.pmmood2*1 * WP Negative Mood: Men lincom c.wpmood*1 + c.women#c.wpmood*0 * WP Negative Mood: Women lincom c.wpmood*1 + c.women#c.wpmood*1 * WP Negative Mood: Sex Diff lincom c.women#c.wpmood*1 * BP Stressors: Men lincom c.stressor*1 + c.women#c.stressor*0 + c.pmstressor40*1 + c.women#c.pmstressor40*0 * BP Stressors: Women lincom c.stressor*1 + c.women#c.stressor*1 + c.pmstressor40*1 + c.women#c.pmstressor40*1 * BP Stressors: Sex Diff lincom c.women#c.stressor*1 + c.women#c.pmstressor40*1 * Contextual Stressors: Men lincom c.pmstressor40*1 + c.women#c.pmstressor40*0 * Contextual Stressors: Women lincom c.pmstressor40*1 + c.women#c.pmstressor40*1 * Contextual Stressors: Sex Diff lincom c.women#c.pmstressor40*1 * WP Stressors: Men lincom c.stressor*1 + c.women#c.stressor*0 * WP Stressors: Women lincom c.stressor*1 + c.women#c.stressor*1 * WP Stressors: Sex Diff lincom c.women#c.stressor*1 * Contextual Stressors per Day lincom c.pmstressor40*.2 estimates store FitSex4, lrtest FitSex4 FitBPWPStressor, predict PredSex4, xb, corr symptoms PredSex4 display as result "Eq 8.11reduced: Adding Only 2 Sex*Stressors Interactions to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor /// c.women#c.pmstressor40 c.women#c.stressor, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Multivariate Test of 2 Sex Interactions test (c.women#c.pmstressor40=0) (c.women#c.stressor=0) estimates store FitSex2, lrtest FitSex2 FitBPWPStressor, predict PredSex2, xb, corr symptoms PredSex2 display as result "Eq 8.12: Adding 4 Negative Mood*Stressors Interactions to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor /// c.women#c.pmstressor40 c.women#c.stressor /// c.pmmood2#c.stressor c.pmmood2#c.pmstressor40 c.wpmood#c.stressor c.wpmood#c.pmstressor40, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Multivariate Test of 4 Negative Mood*Stressors Interactions test (c.pmmood2#c.stressor=0) (c.pmmood2#c.pmstressor40=0) (c.wpmood#c.stressor=0) (c.wpmood#c.pmstressor40=0) * Intercept: Men lincom _cons*1 + c.women*0 * Intercept: Women lincom _cons*1 + c.women*1 * Intercept: Sex Diff lincom c.women*1 * Age Slope: Men lincom c.age80*1 + c.women#c.age80*0 * Age Slope: Women lincom c.age80*1 + c.women#c.age80*1 * Age Slope: Sex Diff lincom c.women#c.age80*1 * BP Negative Mood lincom c.pmmood2*1 * Contextual Negative Mood lincom c.wpmood*-1 + c.pmmood2*1 * WP Negative Mood lincom c.wpmood*1 * BP Stressors: Men lincom c.stressor*1 + c.women#c.stressor*0 + c.pmstressor40*1 + c.women#c.pmstressor40*0 * BP Stressors: Women lincom c.stressor*1 + c.women#c.stressor*1 + c.pmstressor40*1 + c.women#c.pmstressor40*1 * BP Stressors: Sex Diff lincom c.women#c.stressor*1 + c.women#c.pmstressor40*1 * Contextual Stressors: Men lincom c.pmstressor40*1 + c.women#c.pmstressor40*0 * Contextual Stressors: Women lincom c.pmstressor40*1 + c.women#c.pmstressor40*1 * Contextual Stressors: Sex Diff lincom c.women#c.pmstressor40*1 * WP Stressors: Men lincom c.stressor*1 + c.women#c.stressor*0 * WP Stressors: Women lincom c.stressor*1 + c.women#c.stressor*1 * WP Stressors: Sex Diff lincom c.women#c.stressor*1 * Contextual Stressors per Day lincom c.pmstressor40*.2 * BP Negative Mood by BP Stressors lincom c.pmmood2#c.stressor*1 + c.pmmood2#c.pmstressor40*1 * BP Negative Mood by Contextual Stressors lincom c.pmmood2#c.pmstressor40*1 * BP Negative Mood by WP Stressors lincom c.pmmood2#c.stressor*1 * Contextual Negative Mood by BP Stressors lincom c.wpmood#c.stressor*-1 + c.pmmood2#c.stressor*1 + c.wpmood#c.pmstressor40*-1 + c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by Contextual Stressors lincom c.wpmood#c.pmstressor40*-1 + c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by WP Stressors lincom c.wpmood#c.stressor*-1 + c.pmmood2#c.stressor*1 * WP Negative Mood by BP Stressors lincom c.wpmood#c.stressor*1 + c.wpmood#c.pmstressor40*1 * WP Negative Mood by Contextual Stressors lincom c.wpmood#c.pmstressor40*1 * WP Negative Mood by WP Stressors lincom c.wpmood#c.stressor*1 estimates store FitMoodStressor4, lrtest FitMoodStressor4 FitSex2, predict PredMoodStressor4, xb, corr symptoms PredMoodStressor4 display as result "Ch 8: Checking Inter-Variable Interactions via PMC Negative Mood by PMC Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.wpstressor /// c.women#c.pmstressor40 c.women#c.wpstressor /// c.pmmood2#c.wpstressor c.pmmood2#c.pmstressor40 c.wpmood#c.wpstressor c.wpmood#c.pmstressor40, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * BP Negative Mood by BP Stressors lincom c.pmmood2#c.pmstressor40*1 * BP Negative Mood by Contextual Stressors lincom c.pmmood2#c.wpstressor*-1 + c.pmmood2#c.pmstressor40*1 * BP Negative Mood by WP Stressors lincom c.pmmood2#c.wpstressor*1 * Contextual Negative Mood by BP Stressors lincom c.wpmood#c.pmstressor40*-1 + c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by Contextual Stressors lincom c.wpmood#c.pmstressor40*-1 + c.pmmood2#c.pmstressor40*1 + c.pmmood2#c.wpstressor*-1 + c.wpmood#c.wpstressor*1 * Contextual Negative Mood by WP Stressors lincom c.wpmood#c.wpstressor*-1 + c.pmmood2#c.wpstressor*1 * WP Negative Mood by BP Stressors lincom c.wpmood#c.pmstressor40*1 * WP Negative Mood by Contextual Stressors lincom c.wpmood#c.wpstressor*-1 + c.wpmood#c.pmstressor40*1 * WP Negative Mood by WP Stressors lincom c.wpmood#c.wpstressor*1 display as result "Ch 8: Checking Inter-Variable Interactions via GMC Negative Mood by GMC Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.mood2 c.pmstressor40 c.stressor /// c.women#c.pmstressor40 c.women#c.stressor /// c.pmmood2#c.stressor c.pmmood2#c.pmstressor40 c.mood2#c.stressor c.mood2#c.pmstressor40, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * BP Negative Mood by BP Stressors lincom c.mood2#c.pmstressor40*1 + c.pmmood2#c.pmstressor40*1 + c.stressor#c.pmmood2*1 + c.mood2#c.stressor*1 * BP Negative Mood by Contextual Stressors lincom c.mood2#c.pmstressor40*1 + c.pmmood2#c.pmstressor40*1 * BP Negative Mood by WP Stressors lincom c.pmmood2#c.stressor*1 + c.mood2#c.stressor*1 * Contextual Negative Mood by BP Stressors lincom c.pmmood2#c.stressor*1 + c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by Contextual Stressors lincom c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by WP Stressors lincom c.pmmood2#c.stressor*1 * WP Negative Mood by BP Stressors lincom c.mood2#c.pmstressor40*1 + c.mood2#c.stressor*1 * WP Negative Mood by Contextual Stressors lincom c.mood2#c.pmstressor40*1 * WP Negative Mood by WP Stressors lincom c.mood2#c.stressor*1 display as result "Ch 8: Checking Inter-Variable Interactions via GMC Negative Mood by PMC Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.mood2 c.pmstressor40 c.wpstressor /// c.women#c.pmstressor40 c.women#c.wpstressor /// c.pmmood2#c.wpstressor c.pmmood2#c.pmstressor40 c.mood2#c.wpstressor c.mood2#c.pmstressor40, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * BP Negative Mood by BP Stressors lincom c.mood2#c.pmstressor40*1 + c.pmmood2#c.pmstressor40*1 * BP Negative Mood by Contextual Stressors lincom c.pmmood2#c.wpstressor*-1 + c.mood2#c.wpstressor*-1 + c.mood2#c.pmstressor40*1 + c.pmmood2#c.pmstressor40*1 * BP Negative Mood by WP Stressors lincom c.pmmood2#c.wpstressor*1 + c.mood2#c.wpstressor*1 * Contextual Negative Mood by BP Stressors lincom c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by Contextual Stressors lincom c.pmmood2#c.wpstressor*-1 + c.pmmood2#c.pmstressor40*1 * Contextual Negative Mood by WP Stressors lincom c.pmmood2#c.wpstressor*1 * WP Negative Mood by BP Stressors lincom c.mood2#c.pmstressor40*1 * WP Negative Mood by Contextual Stressors lincom c.mood2#c.wpstressor*-1 + c.mood2#c.pmstressor40*1 * WP Negative Mood by WP Stressors lincom c.mood2#c.wpstressor*1 display as result "Eq 8.13: Adding 5 Intra-Variable Interactions to the Model for the Means" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor /// c.women#c.pmstressor40 c.women#c.stressor /// c.pmmood2#c.pmmood2 c.wpmood#c.wpmood c.pmmood2#c.wpmood c.pmstressor40#c.pmstressor40 c.pmstressor40#c.stressor, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), * Multivariate Test of 5 Intra-Variable Interactions test (c.pmmood2#c.pmmood2=0) (c.wpmood#c.wpmood=0) (c.pmmood2#c.wpmood=0) (c.pmstressor40#c.pmstressor40=0) (c.pmstressor40#c.stressor=0) * BP Negative Mood: Linear lincom c.pmmood2*1 * BP Negative Mood: Quadratic lincom c.pmmood2#c.pmmood2*1 * Contextual Negative Mood: Linear lincom c.wpmood*-1 + c.pmmood2*1 * Contextual Negative Mood: Quadratic lincom c.pmmood2#c.wpmood*-1 + c.pmmood2#c.pmmood2*1 + c.wpmood#c.wpmood*1 * WP Negative Mood: Linear lincom c.wpmood*1 * WP Negative Mood: Quadratic lincom c.wpmood#c.wpmood*1 * BP by WP Negative Mood lincom c.pmmood2#c.wpmood*1 * Contextual by WP Negative Mood lincom c.pmmood2#c.wpmood*1 + c.wpmood#c.wpmood*-2 * BP Stressor: Linear lincom c.pmstressor40*1 + c.stressor*1 * BP Stressor: Quadratic lincom c.pmstressor40#c.pmstressor40*1 + c.pmstressor40#c.stressor*1 * Contextual Stressors: Linear lincom c.pmstressor40*1 * Contextual Stressors: Quadratic lincom c.pmstressor40#c.pmstressor40*1 * WP Stressors: Linear lincom c.stressor*1 * BP/Contextual by WP Stressors lincom c.pmstressor40#c.stressor*1 * BP Negative Mood: Linear at 1 lincom c.pmmood2*1 + c.pmmood2#c.pmmood2*-2 * BP Negative Mood: Linear at 3 lincom c.pmmood2*1 + c.pmmood2#c.pmmood2*2 estimates store FitIntra5, lrtest FitIntra5 FitSex2, predict PredIntra5, xb, corr symptoms PredIntra5 display as result "Eq 8.13reduced: Baseline Homogeneous Variance Model with Significant Fixed Effects Only" display as result "Using Person-Mean-Centering for Negative Mood, Grand-Mean-Centering for Stressors" mixed symptoms c.women c.age80 c.women#c.age80 /// c.pmmood2 c.wpmood c.pmstressor40 c.stressor /// c.women#c.pmstressor40 c.women#c.stressor /// c.pmmood2#c.pmmood2 c.pmmood2#c.wpmood, /// || personid: , variance mle covariance(unstructured), estat ic, n(105), ****** END CHAPTER 8 MODELS ****** * Close log log close STATA_Chapter8 * Convert log to html using custom downloaded package log2html $filesave\STATA_Chapter8_Output, replace