* To respond to posting . * Date: Fri, 9 Jul 2004 15:42:57 -0500 . * Reply-To: Jodene Goldenring Fine . * Sender: "SPSSX(r) Discussion" . * From: Jodene Goldenring Fine . * Subject: changing variable values of cases not the current case . * Compute the value of "jadhd", which is 1 if the person has an ADHD . * dx, 0 otherwise, based on: . * - If person is a child (famem = 0), set if adhdsub > 0 . * - If person is mother (famem = 1), set if child madhddx = 1,4 . * - If person is father (famem = 2), set if child fadhddx = 1,4 . * "After the routine, the data should look like this: . * DATA LIST . * famno famem adhdsub madhdhx fadhdhx jadhd . * 02 0 3 1 0 1 . * 02 1 . . . 1 . * 02 2 . . . 0 . * . * 05 0 0 0 0 0 . * 05 0 0 0 0 0 . * 05 1 . . . 0 . * . * 06 0 0 0 1 1 . * 06 1 . . . 0 . * 06 2 0 0 0 1 . * END DATA DATA LIST LIST SKIP=1/ famno famem adhdsub madhdhx fadhdhx DESIRED. BEGIN DATA. famno famem adhdsub madhdhx fadhdhx jadhd 02 0 3 1 0 1 02 1 . . . 1 02 2 . . . 0 05 0 0 0 0 0 05 0 0 0 0 0 05 1 . . . 0 06 0 0 0 1 1 06 1 . . . 0 06 2 0 0 0 1 END DATA. FORMATS FAMNO (N2) /FAMEM TO DESIRED (F2). VAL LABELS FAMEM 0 'Child' 1 'Mother' 2 'Father'. LIST. FILE HANDLE DATA_IN /NAME= 'c:\TempStor\SPSS\2004-07-09 Fine - ' + 'change values across cases - INPUT.sav'. SAVE OUTFILE=DATA_IN. * Solution using scratch variables . * (This works because scratch variables keep their . * values between cases, like regular variables with . * LEAVE specified.) . * Put in order: families together, children before . * parents . SORT CASES BY FAMNO FAMEM. * Declare output variable and two scratch variables . NUMERIC JADHD (F1). VAR LABELS JADHD 'Individual has ADHD Dx'. VAL LABELS JADHD 0 'No Dx' 1 'Dx'. NUMERIC #MADHD /* Mother has ADHD Dx */ #FADHD (F1). /* Father has ADHD Dx */ * At start of a family, reset the scratch variables . * (Another way to identify start of a family: . * "MATCH FILES/FILE=*/BY FAMNO/FIRST=NEW_FMLY") . DO IF MISSING(LAG(FAMNO)). . COMPUTE #MADHD = $SYSMIS. . COMPUTE #FADHD = $SYSMIS. ELSE IF LAG(FAMNO) NE FAMNO. . COMPUTE #MADHD = $SYSMIS. . COMPUTE #FADHD = $SYSMIS. END IF. * Computation: . DO IF FAMEM = 0. /* Child */ . COMPUTE JADHD = (ADHDSUB > 0). * The following resolves ambiguity by assigning a . * Dx to the parent if ANY child record records a . * parental Dx. . . COMPUTE #MADHD = MAX(#MADHD,ANY(MADHDHX,1,4)). . COMPUTE #FADHD = MAX(#FADHD,ANY(FADHDHX,1,4)). ELSE IF FAMEM = 1. /* Mother */ . COMPUTE JADHD = #MADHD. ELSE IF FAMEM = 2. /* Father */ . COMPUTE JADHD = #FADHD. END IF. LIST.