Dear all,
For each of my cases, I would like to compute 4 new variables, those being the medians across respectively: - a set of 4 variables (q17 TO q41). Their valid values range from 1 to 3. - a set of 166 variables (q19a TO q81g) . Their valid values range from 1 to 4. - a set of 31 variables (q55 TO q76y). Their valid values range from 1 to 5. - a set of 10 variables (LADDSCH TO LADDAUS). Their valid values range from 1 to 10. In my data set, all those variables are already placed one after the other. There are all numeric (ordinal level). Some cases have many missing values. The missing values are encoded as "99", "88", "77", and "0". I started to ask SPSS to split the file per case. But then SPSS (version 14) apparently has a function for the MEAN but none for the median under COMPUTE so that's only how far I got! Thanks for any hint, Regards, Aude Aude Plontz The Good Starts Project Refugee Health Research Centre Phone: at home: +61 (0)3 9917 2134 at La Trobe University (on most Thursdays): +61 (0)3 9479 3161 (desk, room 475, Martin Building, 9-10am, 2.30-5.00pm) or +61 (0)3 9479 5874 (Estelle Purchas, RHRC secretary) at the Victorian Foundation for Survivors of Torture (some Tuesdays or Wednesdays): +61 (0)3 9940 1567 (desk, Brunswick Business Incubator) or +61 (0)3 9388 0022 (reception) Email: [hidden email] [hidden email] [hidden email] |
There is a median function that works across variables available with SPSS 15 (sorry) programmability. Here is the code, followed by an explanation.
* Using gss data file. begin program. import spss, spssaux, trans, extendedTransforms varDict = spssaux.VariableDict() hlthvars = varDict.range(start="hlth1", end="hlth9") workvars = varDict.range(start="work1", end="work9") t = trans.Tfunction() t.append(extendedTransforms.median, "medianHlth", "f", hlthvars) t.append(extendedTransforms.median, "medianWork", "f", workvars) t.execute() end program. The import loads several modules that can be downloaded from SPSS Developer Central (www.spss.com/devcentral). The varDict line constructs a Python dictionary of all the variables in the SPSS data file. hlthvars = and workvars = construct lists of variable names and are equivalent to hlth1 TO hlth9 and work1 TO work9. t = starts defining a set of transformations. The t.append lines define new variables (f format) that are the result of using the median function in the extendedTransforms module with input of the corresponding variable list t.execute actually passes the data and constructs the variables. You do need at least SPSS 15.0.1 and Python programmability installed for this to work. Regards, Jon Peck SPSS -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of AUDE MARIE PLONTZ Sent: Friday, April 13, 2007 12:06 AM To: [hidden email] Subject: [SPSSX-L] Ipsative median computation with SPSS 14 Dear all, For each of my cases, I would like to compute 4 new variables, those being the medians across respectively: - a set of 4 variables (q17 TO q41). Their valid values range from 1 to 3. - a set of 166 variables (q19a TO q81g) . Their valid values range from 1 to 4. - a set of 31 variables (q55 TO q76y). Their valid values range from 1 to 5. - a set of 10 variables (LADDSCH TO LADDAUS). Their valid values range from 1 to 10. In my data set, all those variables are already placed one after the other. There are all numeric (ordinal level). Some cases have many missing values. The missing values are encoded as "99", "88", "77", and "0". I started to ask SPSS to split the file per case. But then SPSS (version 14) apparently has a function for the MEAN but none for the median under COMPUTE so that's only how far I got! Thanks for any hint, Regards, Aude Aude Plontz The Good Starts Project Refugee Health Research Centre Phone: at home: +61 (0)3 9917 2134 at La Trobe University (on most Thursdays): +61 (0)3 9479 3161 (desk, room 475, Martin Building, 9-10am, 2.30-5.00pm) or +61 (0)3 9479 5874 (Estelle Purchas, RHRC secretary) at the Victorian Foundation for Survivors of Torture (some Tuesdays or Wednesdays): +61 (0)3 9940 1567 (desk, Brunswick Business Incubator) or +61 (0)3 9388 0022 (reception) Email: [hidden email] [hidden email] [hidden email] |
In reply to this post by Aude
At 01:06 AM 4/13/2007, AUDE MARIE PLONTZ wrote:
>I would like to compute 4 new variables, those being the medians >across respectively: >- a set of 4 variables (q17 TO q41). >- a set of 166 variables (q19a TO q81g) . >- a set of 31 variables (q55 TO q76y). >- a set of 10 variables (LADDSCH TO LADDAUS). >All those variables are already placed one after the other. There are >all numeric (ordinal level). Well, I'd 'unroll' using XSAVE, and use MEDIAN in AGGREGATE (which 14 has). The best code I can find is awkward for a number of reasons, including that there can be only one XSAVE for any one file. One could write a loop to write all the 'unrolled' values to one file; I'm writing them to separate files, instead. (The loop to write one file would be very awkward if the four sets were only individually contiguous; it wouldn't be so bad if they were all contiguous, and could all be in a single VECTOR.) I've made a shorter dataset, with three groups of variables of which to take the medians. This is SPSS 14 draft output. List |-----------------------------|---------------------------| |Output Created |13-APR-2007 13:43:31 | |-----------------------------|---------------------------| [InptData] CASE A1 A2 A3 B1 B2 B3 B4 B5 C1 C2 C3 C4 C5 C6 C7 01 1 2 3 6 7 4 3 5 6 4 1 98 8 9 6 02 3 2 2 7 1 98 7 5 8 9 5 9 1 98 1 03 2 1 2 3 7 5 98 6 3 8 98 7 8 9 98 04 3 98 3 98 5 1 98 2 9 1 1 98 98 2 9 05 2 3 3 98 1 7 2 3 98 6 8 8 3 5 5 06 2 2 98 1 1 6 7 3 2 98 7 98 4 7 6 07 3 98 2 4 4 7 4 6 5 98 9 2 8 9 98 08 98 1 2 1 1 4 7 7 6 6 98 2 1 6 98 09 1 3 1 3 1 7 7 7 6 8 6 6 5 2 98 10 1 3 2 5 5 1 1 6 6 8 98 9 98 5 5 Number of cases read: 10 Number of cases listed: 10 * I. Unroll all three sets of variables, each to a separate . * file. . * (UNROLL_A, UNROLL_B, and UNROLL_C are file handles. . * XSAVE can't write to datasets.) . TEMPORARY /* So the following variables aren't added to the */ /* active dataset. */. NUMERIC GrpOrder VarOrder (F3). STRING VarName (A5). NUMERIC VarValue (F2). VECTOR A = A1 TO A3. COMPUTE GrpOrder = 1. COMPUTE VarName = 'A'. LOOP VarOrder = 1 TO 3. . COMPUTE VarValue = A(VarOrder). . XSAVE OUTFILE = UNROLL_A / KEEP = CASE GrpOrder VarOrder VarName VarValue. END LOOP. VECTOR B = B1 TO B5. COMPUTE GrpOrder = 2. COMPUTE VarName = 'B'. LOOP VarOrder = 1 TO 5. . COMPUTE VarValue = B(VarOrder). . XSAVE OUTFILE = UNROLL_B / KEEP = CASE GrpOrder VarOrder VarName VarValue. END LOOP. VECTOR C = C1 TO C7. COMPUTE GrpOrder = 3. COMPUTE VarName = 'C'. LOOP VarOrder = 1 TO 7. . COMPUTE VarValue = C(VarOrder). . XSAVE OUTFILE = UNROLL_C / KEEP = CASE GrpOrder VarOrder VarName VarValue. END LOOP. EXECUTE /* This one is necessary */. * II. Combine all unrolled values in one dataset . ADD FILES /FILE=UNROLL_A /FILE=UNROLL_B /FILE=UNROLL_C /BY CASE GrpOrder VarOrder. DATASET NAME Medians. LIST. List |-----------------------------|---------------------------| |Output Created |13-APR-2007 13:43:35 | |-----------------------------|---------------------------| [Medians] CASE GrpOrder VarOrder VarName VarValue 01 1 1 A 1 01 1 2 A 2 01 1 3 A 3 01 2 1 B 6 01 2 2 B 7 01 2 3 B 4 01 2 4 B 3 01 2 5 B 5 [...] 10 3 1 C 6 10 3 2 C 8 10 3 3 C . 10 3 4 C 9 10 3 5 C . 10 3 6 C 5 10 3 7 C 5 Number of cases read: 150 Number of cases listed: 150 * III. Take the medians . AGGREGATE /OUTFILE = * /BREAK = Case GrpOrder VarName /Median = MEDIAN (VarValue). FORMATS Median (F4.1). LIST. List |-----------------------------|---------------------------| |Output Created |13-APR-2007 13:43:35 | |-----------------------------|---------------------------| CASE GrpOrder VarName Median 01 1 A 2.0 01 2 B 5.0 01 3 C 6.0 02 1 A 2.0 02 2 B 6.0 02 3 C 6.5 03 1 A 2.0 03 2 B 5.5 03 3 C 8.0 04 1 A 3.0 04 2 B 2.0 04 3 C 2.0 05 1 A 3.0 05 2 B 2.5 05 3 C 5.5 06 1 A 2.0 06 2 B 3.0 06 3 C 6.0 07 1 A 2.5 07 2 B 4.0 07 3 C 8.0 08 1 A 1.5 08 2 B 4.0 08 3 C 6.0 09 1 A 1.0 09 2 B 7.0 09 3 C 6.0 10 1 A 2.0 10 2 B 5.0 10 3 C 6.0 Number of cases read: 30 Number of cases listed: 30 * IV. Combine all three medians into one record . CASESTOVARS /ID = CASE /RENAME GrpOrder = Ord Median = Mdn /INDEX = VarName /SEPARATOR = "" /GROUPBY = VARIABLE . Cases to Variables |--------------------------|---------------------------| |Output Created |13-APR-2007 13:43:35 | |--------------------------|---------------------------| Generated Variables |--------|-------|------| |Original|VarName|Result| |Variable| |------| | | |Name | |--------|-------|------| |GrpOrder|A |OrdA | | |B |OrdB | | |C |OrdC | |--------|-------|------| |Median |A |MdnA | | |B |MdnB | | |C |MdnC | |--------|-------|------| Processing Statistics |---------------|---| |Cases In |30 | |Cases Out |10 | |---------------|---| |Cases In/Cases |3.0| |Out | | |---------------|---| |Variables In |4 | |Variables Out |7 | |---------------|---| |Index Values |3 | |---------------|---| LIST. List |-----------------------------|---------------------------| |Output Created |13-APR-2007 13:43:36 | |-----------------------------|---------------------------| CASE OrdA OrdB OrdC MdnA MdnB MdnC 01 1 2 3 2.0 5.0 6.0 02 1 2 3 2.0 6.0 6.5 03 1 2 3 2.0 5.5 8.0 04 1 2 3 3.0 2.0 2.0 05 1 2 3 3.0 2.5 5.5 06 1 2 3 2.0 3.0 6.0 07 1 2 3 2.5 4.0 8.0 08 1 2 3 1.5 4.0 6.0 09 1 2 3 1.0 7.0 6.0 10 1 2 3 2.0 5.0 6.0 Number of cases read: 10 Number of cases listed: 10 * V. Finally, combine with the original data . MATCH FILES /FILE=InptData /FILE=* /BY CASE /DROP=OrdA OrdB OrdC. TEMPORARY. STRING SPACE (A4). LIST CASE TO MdnC SPACE. List |-----------------------------|---------------------------| |Output Created |13-APR-2007 13:43:36 | |-----------------------------|---------------------------| The variables are listed in the following order: LINE 1: CASE A1 A2 A3 B1 B2 B3 B4 B5 C1 C2 C3 C4 C5 C6 C7 LINE 2: MdnA MdnB MdnC SPACE CASE: 01 1 2 3 6 7 4 3 5 6 4 1 98 8 9 6 MdnA: 2.0 5.0 6.0 CASE: 02 3 2 2 7 1 98 7 5 8 9 5 9 1 98 1 MdnA: 2.0 6.0 6.5 CASE: 03 2 1 2 3 7 5 98 6 3 8 98 7 8 9 98 MdnA: 2.0 5.5 8.0 CASE: 04 3 98 3 98 5 1 98 2 9 1 1 98 98 2 9 MdnA: 3.0 2.0 2.0 CASE: 05 2 3 3 98 1 7 2 3 98 6 8 8 3 5 5 MdnA: 3.0 2.5 5.5 CASE: 06 2 2 98 1 1 6 7 3 2 98 7 98 4 7 6 MdnA: 2.0 3.0 6.0 CASE: 07 3 98 2 4 4 7 4 6 5 98 9 2 8 9 98 MdnA: 2.5 4.0 8.0 CASE: 08 98 1 2 1 1 4 7 7 6 6 98 2 1 6 98 MdnA: 1.5 4.0 6.0 CASE: 09 1 3 1 3 1 7 7 7 6 8 6 6 5 2 98 MdnA: 1.0 7.0 6.0 CASE: 10 1 3 2 5 5 1 1 6 6 8 98 9 98 5 5 MdnA: 2.0 5.0 6.0 Number of cases read: 10 Number of cases listed: 10 ==================================== APPENDIX: File handles and test data ==================================== FILE HANDLE UNROLL_A /NAME='C:\Documents and Settings\Richard\My Documents' + '\Temporary\SPSS\' + '2007-04-13 PLONTZ - ' + 'Ipsative median computation with SPSS 14' + ' - ' + 'UNROLL_A.SAV'. FILE HANDLE UNROLL_B /NAME='C:\Documents and Settings\Richard\My Documents' + '\Temporary\SPSS\' + '2007-04-13 PLONTZ - ' + 'Ipsative median computation with SPSS 14' + ' - ' + 'UNROLL_B.SAV'. FILE HANDLE UNROLL_C /NAME='C:\Documents and Settings\Richard\My Documents' + '\Temporary\SPSS\' + '2007-04-13 PLONTZ - ' + 'Ipsative median computation with SPSS 14' + ' - ' + 'UNROLL_C.SAV'. * ................................................... . * ............ Test data ............ . SET RNG = MT /* 'Mersenne twister' random number generator */. SET MTINDEX = 7778 /* Providence, RI telephone book */. INPUT PROGRAM. . NUMERIC CASE (N2). . NUMERIC A1 TO A3 B1 TO B5 C1 TO C7 (F3). . MISSING VAL A1 TO A3 B1 TO B5 C1 TO C7 (98). . VECTOR A = A1 TO A3 /B = B1 TO B5 /C = C1 TO C7. . LOOP CASE = 1 TO 10. . LOOP #IDX = 1 TO 3. . COMPUTE A(#IDX) = TRUNC(RV.UNIFORM(1,4)). . IF RV.UNIFORM(0,1) LE 0.2 A(#IDX) = 98. . END LOOP. . LOOP #IDX = 1 TO 5. . COMPUTE B(#IDX) = TRUNC(RV.UNIFORM(1,8)). . IF RV.UNIFORM(0,1) LE 0.2 B(#IDX) = 98. . END LOOP. . LOOP #IDX = 1 TO 7. . COMPUTE C(#IDX) = TRUNC(RV.UNIFORM(1,10)). . IF RV.UNIFORM(0,1) LE 0.2 C(#IDX) = 98. . END LOOP. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME InptData. |
In reply to this post by Aude
At 01:52 PM 4/13/2007, Richard Ristow wrote:
>At 01:06 AM 4/13/2007, AUDE MARIE PLONTZ wrote: > >>I would like to compute 4 new variables, those being the medians >>across respectively: >>- a set of 4 variables (q17 TO q41). >>- a set of 166 variables (q19a TO q81g) . >>- a set of 31 variables (q55 TO q76y). >>- a set of 10 variables (LADDSCH TO LADDAUS). >>All those variables are already placed one after the other. There are >>all numeric (ordinal level). > >Well, I'd 'unroll' using XSAVE, and use MEDIAN in AGGREGATE (which 14 >has). The best code I can find is awkward for a number of reasons... The following is a substantial rework. I used XSAVE because I didn't think VARSTOCASES could handle the job; but I found a way to use VARSTOCASES that works very well. I think the code is substantially simpler. |-----------------------------|---------------------------| |Output Created |14-APR-2007 23:30:30 | |-----------------------------|---------------------------| [InptData] CASE A1 A2 A3 B1 B2 B3 B4 B5 C1 C2 C3 C4 C5 C6 C7 01 1 2 3 6 7 4 3 5 6 4 1 98 8 9 6 02 3 2 2 7 1 98 7 5 8 9 5 9 1 98 1 03 2 1 2 3 7 5 98 6 3 8 98 7 8 9 98 04 3 98 3 98 5 1 98 2 9 1 1 98 98 2 9 05 2 3 3 98 1 7 2 3 98 6 8 8 3 5 5 06 2 2 98 1 1 6 7 3 2 98 7 98 4 7 6 07 3 98 2 4 4 7 4 6 5 98 9 2 8 9 98 08 98 1 2 1 1 4 7 7 6 6 98 2 1 6 98 09 1 3 1 3 1 7 7 7 6 8 6 6 5 2 98 10 1 3 2 5 5 1 1 6 6 8 98 9 98 5 5 Number of cases read: 10 Number of cases listed: 10 * I. Unroll the three sets of variables . * . * MAJOR CHANGE from first posted version (V01): . * Use logic with VARSTOCASES logic, instead of XSAVE. . * (I didn't think VARSTOCASES could work, but have seen a way.). * . * . Simpler, clearer logic. . * . Unroll all three sets in one step; no need to re-combine . * . Can work with datasets; does not need scratch .SAV files . DATASET COPY Medians. DATASET ACTIVATE Medians. VARSTOCASES /MAKE VarValue FROM A1 TO A3 B1 TO B5 C1 TO C7 /INDEX VarName (VarValue). Variables to Cases |----------------------------|---------------------------| |Output Created |14-APR-2007 23:30:34 | |----------------------------|---------------------------| [Medians] Generated Variables |--------|------| |Name |Label | |--------|------| |VarName |<none>| |VarValue|<none>| |--------|------| Processing Statistics |-------------|--| |Variables In |16| |Variables Out|3 | |-------------|--| *(II. Combine all unrolled values in one dataset) . * (NOT NECESSARY in this version; all unrolled values are . * created in the same dataset to start with.) * II. Identify groups of variables to be aggregated . * (ADDED in this version; in the XSAVE logic, group . * identification was intrinsic.) . NUMERIC GrpOrder (F3). STRING GrpName (A8). * In cases like this one, the following logic could be simpler:. * the group name is a substring of the variable name. . * However, this logic works with variable names of any form, . * including ones like those in the original posting. . LEAVE GrpOrder GrpName. DO IF VarName EQ 'A1' /* First variable in first group */ . . COMPUTE GrpOrder = 1 . . COMPUTE GrpName = 'A'. ELSE IF VarName EQ 'B1' /* First variable in second group */ . . COMPUTE GrpOrder = 2 . . COMPUTE GrpName = 'B'. ELSE IF VarName EQ 'C1' /* First variable in third group */ . . COMPUTE GrpOrder = 3 . . COMPUTE GrpName = 'C'. END IF. LIST. List |-----------------------------|---------------------------| |Output Created |14-APR-2007 23:30:35 | |-----------------------------|---------------------------| [Medians] CASE VarName VarValue GrpOrder GrpName 01 A1 1 1 A 01 A2 2 1 A 01 A3 3 1 A 01 B1 6 2 B 01 B2 7 2 B 01 B3 4 2 B 01 B4 3 2 B [...] 10 B5 6 2 B 10 C1 6 3 C 10 C2 8 3 C 10 C3 98 3 C 10 C4 9 3 C 10 C5 98 3 C 10 C6 5 3 C 10 C7 5 3 C Number of cases read: 150 Number of cases listed: 150 * III. Take the medians . * (Unchanged) . AGGREGATE /OUTFILE = * /BREAK = Case GrpOrder GrpName /Median = MEDIAN (VarValue). FORMATS Median (F3.1). LIST. List |-----------------------------|---------------------------| |Output Created |14-APR-2007 23:30:36 | |-----------------------------|---------------------------| CASE GrpOrder GrpName Median 01 1 A 2.0 01 2 B 5.0 01 3 C 6.0 02 1 A 2.0 02 2 B 6.0 02 3 C 6.5 03 1 A 2.0 03 2 B 5.5 03 3 C 8.0 04 1 A 3.0 04 2 B 2.0 04 3 C 2.0 05 1 A 3.0 05 2 B 2.5 05 3 C 5.5 06 1 A 2.0 06 2 B 3.0 06 3 C 6.0 07 1 A 2.5 07 2 B 4.0 07 3 C 8.0 08 1 A 1.5 08 2 B 4.0 08 3 C 6.0 09 1 A 1.0 09 2 B 7.0 09 3 C 6.0 10 1 A 2.0 10 2 B 5.0 10 3 C 6.0 Number of cases read: 30 Number of cases listed: 30 * IV. Combine all three medians into one record . * (Unchanged) . CASESTOVARS /ID = CASE /RENAME GrpOrder = Ord Median = Mdn /INDEX = GrpName /SEPARATOR = "" /GROUPBY = VARIABLE . Cases to Variables |--------------------------|---------------------------| |Output Created |14-APR-2007 23:30:36 | |--------------------------|---------------------------| Generated Variables |--------|-------|------| |Original|GrpName|Result| |Variable| |------| | | |Name | |--------|-------|------| |GrpOrder|A |OrdA | | |B |OrdB | | |C |OrdC | |--------|-------|------| |Median |A |MdnA | | |B |MdnB | | |C |MdnC | |--------|-------|------| Processing Statistics |---------------|---| |Cases In |30 | |Cases Out |10 | |---------------|---| |Cases In/Cases |3.0| |Out | | |---------------|---| |Variables In |4 | |Variables Out |7 | |---------------|---| |Index Values |3 | |---------------|---| LIST. List |-----------------------------|---------------------------| |Output Created |14-APR-2007 23:30:36 | |-----------------------------|---------------------------| CASE OrdA OrdB OrdC MdnA MdnB MdnC 01 1 2 3 2.0 5.0 6.0 02 1 2 3 2.0 6.0 6.5 03 1 2 3 2.0 5.5 8.0 04 1 2 3 3.0 2.0 2.0 05 1 2 3 3.0 2.5 5.5 06 1 2 3 2.0 3.0 6.0 07 1 2 3 2.5 4.0 8.0 08 1 2 3 1.5 4.0 6.0 09 1 2 3 1.0 7.0 6.0 10 1 2 3 2.0 5.0 6.0 Number of cases read: 10 Number of cases listed: 10 * V. Finally, combine with the original data . * (Unchanged) . MATCH FILES /FILE=InptData /FILE=* /BY CASE /DROP=OrdA OrdB OrdC. TEMPORARY. STRING CaseSpce (A60) DataSpce (A4). LIST CASE CaseSpce A1 TO C7 DataSpce MdnA TO MdnC. List |-----------------------------|---------------------------| |Output Created |14-APR-2007 23:31:30 | |-----------------------------|---------------------------| The variables are listed in the following order: LINE 1: CASE CaseSpce LINE 2: A1 A2 A3 B1 B2 B3 B4 B5 C1 C2 C3 C4 C5 C6 C7 DataSpce LINE 3: MdnA MdnB MdnC CASE: 01 A1: 1 2 3 6 7 4 3 5 6 4 1 98 8 9 6 MdnA: 2.0 5.0 6.0 CASE: 02 A1: 3 2 2 7 1 98 7 5 8 9 5 9 1 98 1 MdnA: 2.0 6.0 6.5 CASE: 03 A1: 2 1 2 3 7 5 98 6 3 8 98 7 8 9 98 MdnA: 2.0 5.5 8.0 CASE: 04 A1: 3 98 3 98 5 1 98 2 9 1 1 98 98 2 9 MdnA: 3.0 2.0 2.0 CASE: 05 A1: 2 3 3 98 1 7 2 3 98 6 8 8 3 5 5 MdnA: 3.0 2.5 5.5 CASE: 06 A1: 2 2 98 1 1 6 7 3 2 98 7 98 4 7 6 MdnA: 2.0 3.0 6.0 CASE: 07 A1: 3 98 2 4 4 7 4 6 5 98 9 2 8 9 98 MdnA: 2.5 4.0 8.0 CASE: 08 A1: 98 1 2 1 1 4 7 7 6 6 98 2 1 6 98 MdnA: 1.5 4.0 6.0 CASE: 09 A1: 1 3 1 3 1 7 7 7 6 8 6 6 5 2 98 MdnA: 1.0 7.0 6.0 CASE: 10 A1: 1 3 2 5 5 1 1 6 6 8 98 9 98 5 5 MdnA: 2.0 5.0 6.0 Number of cases read: 10 Number of cases listed: 10 ================================================== APPENDIX: Test data (slight modification to logic) ================================================== * ............ Test data ............ . SET RNG = MT /* 'Mersenne twister' random number generator */. SET MTINDEX = 7778 /* Providence, RI telephone book */. INPUT PROGRAM. . NUMERIC CASE (N2). . NUMERIC A1 TO A3 B1 TO B5 C1 TO C7 (F3). . MISSING VAL A1 TO A3 B1 TO B5 C1 TO C7 (98). . VECTOR A = A1 TO A3 /B = B1 TO B5 /C = C1 TO C7. . LOOP CASE = 1 TO 10. . LOOP #IDX = 1 TO 3. . COMPUTE A(#IDX) = TRUNC(RV.UNIFORM(1,4)). . IF RV.BERNOULLI(0.2) A(#IDX) = 98. . END LOOP. . LOOP #IDX = 1 TO 5. . COMPUTE B(#IDX) = TRUNC(RV.UNIFORM(1,8)). . IF RV.BERNOULLI(0.2) B(#IDX) = 98. . END LOOP. . LOOP #IDX = 1 TO 7. . COMPUTE C(#IDX) = TRUNC(RV.UNIFORM(1,10)). . IF RV.BERNOULLI(0.2) C(#IDX) = 98. . END LOOP. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME InptData. * ............ Post after this point ............ . * ................................................... . LIST. |
Free forum by Nabble | Edit this page |