TITLE:
  Eq 9.3: Multivariate Longitudinal Model using MLM Syntax
  Across-Variable Relationships via Covariances

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

DEFINE:
  agesq = agec18*agec18;

VARIABLE:
  NAMES = PersonID att12 PMmon copymon18 occasion age risky monitor agec18 att4
          mon3 PMmon3 WPmon A18mon3 Ch18mon;
  USEVARIABLES = risky mon3 att4 agec18 agesq;
  MISSING = ALL (-9999);
  CLUSTER = PersonID;
  WITHIN = agec18 agesq;
  BETWEEN = att4;

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

MODEL:

%WITHIN%
  risky mon3 (Rresvar Mresvar);
  risky WITH mon3 (RresMres);
  Rlin | risky ON agec18;
  Mlin | mon3 ON agec18;
  Rquad | risky ON agesq;

%BETWEEN%
  [risky mon3 Rlin Mlin Rquad] (bRint bMint bRlin bMlin bRquad);
  risky mon3 Rlin Mlin Rquad@0 (Rintvar Mintvar Rlinvar Mlinvar Rquadvar);
  risky WITH Rlin  (RintRlin);
  mon3  WITH Mlin  (MintMlin);
  risky WITH mon3  (RintMint);
  Rlin  WITH Mlin  (RlinMlin);
  risky WITH Mlin  (RintMlin);
  Rlin  WITH mon3  (RlinMint);
  risky Rlin ON att4 (battRint battRlin);

MODEL CONSTRAINT:
  NEW(WPresc BPintc BPlinc BPRIRLc BPMIMLc BPRIMLc BPRLMIc);
! WP Residual Correlation
  WPresc  = RresMres / (SQRT(Rresvar)*SQRT(Mresvar));
! BP Intercept Correlation
  BPintc  = RintMint / (SQRT(Rintvar)*SQRT(Mintvar));
! BP Linear Age Slope Correlation
  BPlinc  = RlinMlin / (SQRT(Rlinvar)*SQRT(Mlinvar));
! BP Risky Intercept - Linear Age Slope Correlation
  BPRIRLc = RintRlin / (SQRT(Rintvar)*SQRT(Rlinvar));
! BP Monitor Intercept - Linear Age Slope Correlation
  BPMIMLc = MintMlin / (SQRT(Mintvar)*SQRT(Mlinvar));
! BP Risky Intercept - Monitor Linear Age Slope Correlation
  BPRIMLc = RintMlin / (SQRT(Rintvar)*SQRT(Mlinvar));
! BP Risky Linear Age Slope - Monitor Intercept Correlation
  BPRLMIc = RlinMint / (SQRT(Rlinvar)*SQRT(Mintvar));