TITLE:
  Eq 9.2: Adding Within-Person Monitoring by Quadratic Age
  Using Change from Age 18 Monitoring as Within-Person Monitoring

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

DEFINE:
  agesq = agec18*agec18;
  Chage = agec18*Ch18mon;
  Chagesq = agec18*agec18*Ch18mon;

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

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

MODEL:

%WITHIN%
  risky;
  linear | risky ON agec18;
  quad | risky ON agesq;
  L1mon | risky ON Ch18mon;
  L1age | risky ON Chage;
  L1agesq | risky ON Chagesq;

%BETWEEN%
  [risky linear quad L1mon L1age L1agesq] (int bagec18 bagesq bCh18mon bChage bChagesq);
  risky linear quad@0 L1mon@0 L1age@0 L1agesq@0;
  risky WITH linear;
  risky linear ON att4 (battint battlin);
  risky linear quad ON A18mon3 (b18int b18lin b18quad);

MODEL CONSTRAINT:
  NEW(est1-est8);
! est1: Effect of Age 18 Monitoring at Age 12
  est1 = b18int*1 - b18lin*6 + b18quad*36;
! est2: Effect of Age 18 Monitoring at Age 14
  est2 = b18int*1 - b18lin*4 + b18quad*16;
! est3: Effect of Age 18 Monitoring at Age 16
  est3 = b18int*1 - b18lin*2 + b18quad*4;
! est4: Effect of Age 18 Monitoring at Age 18
  est4 = b18int*1 + b18lin*0 + b18quad*0;
! est5: Effect of Change in Monitoring at Age 12
  est5 = bCh18mon*1 - bChage*6 + bChagesq*36;
! est6: Effect of Change in Monitoring at Age 14
  est6 = bCh18mon*1 - bChage*4 + bChagesq*16;
! est7: Effect of Change in Monitoring at Age 16
  est7 = bCh18mon*1 - bChage*2 + bChagesq*4;
! est8: Effect of Change in Monitoring at Age 18
  est8 = bCh18mon*1 + bChage*0 + bChagesq*0;