TITLE:
  Eq 9.5: Truly Multivariate Longitudinal Model using MLM Syntax
  Across-Variable Relationships via Directed Paths

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);
  WPres | risky ON mon3;
  Rlin | risky ON agec18;
  Mlin | mon3 ON agec18;
  Rquad | risky ON agesq;

%BETWEEN%
  [risky mon3 Rlin Mlin Rquad WPres] (bRint bMint bRlin bMlin bRquad bWPres);
  risky mon3 Rlin Mlin Rquad@0 (Rintvar Mintvar Rlinvar Mlinvar Rquadvar);
  WPres@0 (bWPrvar);
  risky WITH Rlin (RintRlin);
  mon3  WITH Mlin (MintMlin);
  risky ON   mon3 (bIntCont);
  Rlin  ON   Mlin (bLinCont);
  risky ON   Mlin (bML2RIBP);
  Rlin  ON   mon3 (bMI2RLBP);
  risky Rlin ON att4 (battRint battRlin);

MODEL CONSTRAINT:
  NEW(BPRIRLc BPMIMLc BPIntEff BPLinEff WPresStd BPIntStd BPLinStd BPI2Lstd BPL2Istd);
! BP Risky Intercept - Risky Linear Age Slope Correlation
  BPRIRLc  = RintRlin / (SQRT(Rintvar)*SQRT(Rlinvar));
! BP Monitor Intercept - Monitor Linear Age Slope Correlation
  BPMIMLc  = MintMlin / (SQRT(Mintvar)*SQRT(Mlinvar));
! BP Monitor Intercept to Risky Intercept Fixed Effect
  BPIntEff = bWPres + bIntCont;
! BP Monitor Linear Age Slope to Risky Slope Fixed Effect
  BPLinEff = bWPres + bLinCont;
! STD WP Monitor Residual to Risky Residual Fixed Effect
  WPresStd = bWPres   * SQRT(Mresvar) / SQRT(Rresvar);
! STD BP Monitor Intercept to Risky Intercept Fixed Effect
  BPIntStd = BPIntEff * SQRT(Mintvar) / SQRT(Rintvar);
! STD BP Monitor Linear Age Slope to Risky Slope Fixed Effect
  BPLinStd = BPLinEff * SQRT(Mlinvar) / SQRT(Rlinvar);
! STD BP Monitor Linear Age Slope to Risky Intercept Fixed Effect
  BPL2Istd = bML2RIBP * SQRT(Mlinvar) / SQRT(Rintvar);
! STD BP Monitor Intercept to Risky Linear Age Slope Fixed Effect
  BPI2Lstd = bMI2RLBP * SQRT(Mintvar) / SQRT(Rlinvar);