TITLE:
  Ch 4: Empty Means, Random Intercept in G
  4-Lag Toeplitz Heterogeneous R

DATA:
  FILE = MPLUS_Chapter4.csv;
  FORMAT = FREE;

DATA LONGTOWIDE:
  LONG = posmood;
  WIDE = posmood1-posmood7;
  IDVARIABLE = PersonID;
  REPETITION = studyday (1-7);

VARIABLE:
  NAMES = PersonID studyday posmood;
  USEVARIABLES = posmood1-posmood7;
  MISSING = ALL (-9999);

ANALYSIS:
  ESTIMATOR = ML;
  PROCESSORS = 4;

OUTPUT:
  STDYX;

MODEL:
  RandInt BY posmood1-posmood7@1;
  RandInt (intvar);
  posmood1-posmood7 (resvar1-resvar7);
  posmood1-posmood6 PWITH posmood2-posmood7 (rescov1-rescov6);
  posmood1-posmood5 PWITH posmood3-posmood7 (rescov7-rescov11);
  posmood1-posmood4 PWITH posmood4-posmood7 (rescov12-rescov15);
  posmood1-posmood3 PWITH posmood5-posmood7 (rescov16-rescov18);
  [posmood1-posmood7@0 RandInt];

MODEL CONSTRAINT:
  NEW(TOEPcor1 TOEPcor2 TOEPcor3 TOEPcor4);
! Residual Covariance for Studyday 1 and 2
  rescov1  = TOEPcor1*SQRT(resvar1)*SQRT(resvar2);
! Residual Covariance for Studyday 2 and 3
  rescov2  = TOEPcor1*SQRT(resvar2)*SQRT(resvar3);
! Residual Covariance for Studyday 3 and 4
  rescov3  = TOEPcor1*SQRT(resvar3)*SQRT(resvar4);
! Residual Covariance for Studyday 4 and 5
  rescov4  = TOEPcor1*SQRT(resvar4)*SQRT(resvar5);
! Residual Covariance for Studyday 5 and 6
  rescov5  = TOEPcor1*SQRT(resvar5)*SQRT(resvar6);
! Residual Covariance for Studyday 6 and 7
  rescov6  = TOEPcor1*SQRT(resvar6)*SQRT(resvar7);
! Residual Covariance for Studyday 1 and 3
  rescov7  = TOEPcor2*SQRT(resvar1)*SQRT(resvar3);
! Residual Covariance for Studyday 2 and 4
  rescov8  = TOEPcor2*SQRT(resvar2)*SQRT(resvar4);
! Residual Covariance for Studyday 3 and 5
  rescov9  = TOEPcor2*SQRT(resvar3)*SQRT(resvar5);
! Residual Covariance for Studyday 4 and 6
  rescov10 = TOEPcor2*SQRT(resvar4)*SQRT(resvar6);
! Residual Covariance for Studyday 5 and 7
  rescov11 = TOEPcor2*SQRT(resvar5)*SQRT(resvar7);
! Residual Covariance for Studyday 1 and 4
  rescov12 = TOEPcor3*SQRT(resvar1)*SQRT(resvar4);
! Residual Covariance for Studyday 2 and 5
  rescov13 = TOEPcor3*SQRT(resvar2)*SQRT(resvar5);
! Residual Covariance for Studyday 3 and 6
  rescov14 = TOEPcor3*SQRT(resvar3)*SQRT(resvar6);
! Residual Covariance for Studyday 4 and 7
  rescov15 = TOEPcor3*SQRT(resvar4)*SQRT(resvar7);
! Residual Covariance for Studyday 1 and 5
  rescov16 = TOEPcor4*SQRT(resvar1)*SQRT(resvar5);
! Residual Covariance for Studyday 2 and 6
  rescov17 = TOEPcor4*SQRT(resvar2)*SQRT(resvar6);
! Residual Covariance for Studyday 3 and 7
  rescov18 = TOEPcor4*SQRT(resvar3)*SQRT(resvar7);