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

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

DATA LONGTOWIDE:
  LONG = agec18 | risky | mon3;
  WIDE = age12-age18 | risky12-risky18 | mon12-mon18;
  IDVARIABLE = PersonID;
  REPETITION = occasion (12-18);

VARIABLE:
  NAMES = PersonID att12 PMmon copymon18 occasion age risky monitor agec18 att4
          mon3 PMmon3 WPmon A18mon3 Ch18mon;
  USEVARIABLES = att4 age12-age18 risky12-risky18 mon12-mon18;
  MISSING = ALL (-9999);
  TSCORES = age12-age18;

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

MODEL:
  Rint Rlin Rquad | risky12-risky18 AT age12-age18;
  Mint Mlin | mon12-mon18 AT age12-age18;
  [risky12-risky18@0 mon12-mon18@0];
  risky12-risky18 (Rresvar);
  mon12-mon18 (Mresvar);
  risky12-risky18 PON mon12-mon18 (bWPres);
  [Rint Mint Rlin Mlin Rquad] (bRint bMint bRlin bMlin bRquad);
  Rint Mint Rlin Mlin Rquad@0 (Rintvar Mintvar Rlinvar Mlinvar Rquadvar);
  Rint WITH Rlin (RintRlin);
  Mint WITH Mlin (MintMlin);
  Rint ON   Mint (bIntCont);
  Rlin ON   Mlin (bLinCont);
  Rint ON   Mlin (bML2RIBP);
  Rlin ON   Mint (bMI2RLBP);
  Rint 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);