TITLE:
  Eq 10b.7: Piecewise Session Slopes by Observed Burst
  Three-Level Model for the Variance for Positive Affect

DATA:
  ! Prior necessary data manipulation conducted using other programs
  FILE = MPLUS_Chapter10b.csv;
  FORMAT = FREE;

DEFINE:
  ! Dummy code burst
  DO (1, 4) b#=0;
  DO (1, 4) IF burst==# THEN b#=1;

VARIABLE:
  NAMES = PersonID burst session symptoms posaff slope12 slope26 burst1 b1or2;
  USEVARIABLES = posaff slope12 slope26 b1-b4;
  MISSING = ALL (-9999);
  CLUSTER = PersonID burst;
  WITHIN = slope12 slope26;
  BETWEEN = (burst) b1-b4;

ANALYSIS:
  ESTIMATOR = ML;
  PROCESSORS = 4;
  TYPE = THREELEVEL RANDOM;

MODEL:

%WITHIN%
  posaff;
  slope1 | posaff ON slope12;
  slope2 | posaff ON slope26;

%BETWEEN burst%
  posaff slope1@0 slope2@0;
  bdif1 | posaff ON b1;
  bdif2 | posaff ON b2;
  bdif3 | posaff ON b3;
  bdif4 | posaff ON b4;
  slope1 slope2 ON b1 (b1sdif12 b1sdif26);
  slope1 slope2 ON b2 (b2sdif12 b2sdif26);
  slope1 slope2 ON b3 (b3sdif12 b3sdif26);
  slope1 slope2 ON b4 (b4sdif12 b4sdif26);

%BETWEEN PersonID%
  [posaff slope1 slope2 bdif1-bdif4] (int bslope12 bslope26 bbdif1-bbdif4);
  posaff slope1@0 slope2@0 bdif1-bdif4@0;

MODEL CONSTRAINT:
  NEW(est1-est15);
! est1: Session 2 at Burst 1
  est1 = int + bbdif1;
! est2: Session 2 at Burst 2
  est2 = int + bbdif2;
! est3: Session 2 at Burst 3
  est3 = int + bbdif3;
! est4: Session 2 at Burst 4
  est4 = int + bbdif4;
! est5: Session 2 at Burst 5
  est5 = int;
! est6: Slope12 at Burst 1
  est6 = bslope12 + b1sdif12;
! est7: Slope12 at Burst 2
  est7 = bslope12 + b2sdif12;
! est8: Slope12 at Burst 3
  est8 = bslope12 + b3sdif12;
! est9: Slope12 at Burst 4
  est9 = bslope12 + b4sdif12;
! est10: Slope12 at Burst 5
  est10 = bslope12;
! est11: Slope26 at Burst 1
  est11 = bslope26 + b1sdif26;
! est12: Slope26 at Burst 2
  est12 = bslope26 + b2sdif26;
! est13: Slope26 at Burst 3
  est13 = bslope26 + b3sdif26;
! est14: Slope26 at Burst 4
  est14 = bslope26 + b4sdif26;
! est15: Slope26 at Burst 5
  est15 = bslope26;