Dear all,
after you (and thanks so much to Richard and Jon!) helped me having SPSS version 14 compute ipsative medians (= median for each case, and not the median for a specified variable), I felt ready to go to the next step of my analysis... and got lost again. What I would like to do using SPSS Version 14: I would like to have a variable indicating for each case and for each set of variables (sets A, B, C, and D) how many answers are above the value indicated in the variables MdnA, MdnB, MdnC, and MdnD respectively. Please see the example below, applied to Set A and the first 2 cases, the last column of the table showing which kind of data I would like to obtain for each set of variables (SupMdnA, which is the number of answers above MdnA): q17 q18 ENGL q41 MdnA SupMdnA Case 1 1 1 2 2 2 0 Case 2 1 2 3 3 3 1 I started with âCOUNT InfMdnA = q17 TO q41 (LO THRU MdnA)â (intending to continue with âCOMPUTE SupMdnA = 3 - InfMdnAâ) but one cantâ do that. Any ideas out there? How does my data look like? I have: 1. a set of 4 variables (q17 TO q41)(which I will call set A for our purposes). Their valid values range from 1 to 3. 2. a set of 166 variables (q19a TO q81g)(which I will call set B for our purposes). Their valid values range from 1 to 4. 3. a set of 31 variables (q55 TO q76y)(which I will call set C for our purposes). Their valid values range from 1 to 5. 4. a set of 10 variables (LADDSCH TO LADDAUS)(which I will call set D for our purposes). Their valid values range from 1 to 10. ⢠All those 4 sets are placed directly one after the other. The data are all numeric (ordinal level). Some cases have many missing values. The missing values are encoded as "99", "88", "77", and "0". Then I have 4 ipsative median variables, corresponding to each set described ion the above: 1. The variable âMdnAâ indicates the median for each case across the variables in set A. 2. The variable âMdnBâ indicates the median for each case across the variables in set B. 3. The variable âMdnCâ indicates the median for each case across the variables in set C. 4. The variable âMdnDâ indicates the median for each case across the variables in set D. Thanks hips, Below I pasted the syntax I used to compute the ipsative medians, based on what Richard sent me, just in case it would be any help. Aude *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". *From: Richard Ristow [[hidden email]] *Sent: Saturday, 14 April 2007 3:53 AM *To: AUDE MARIE PLONTZ; [hidden email] *Subject: Re: Ipsative median computation with SPSS 14 *Well, I'd 'unroll' using XSAVE (XSAVE produces an SPSS-format data file. SAVE also creates SPSS-format data files. The principal difference is that XSAVE is *not executed until data are read for the next procedure, while SAVE is executed by itself. Thus, XSAVE can reduce processing time by consolidating two data *passes into one.), 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. 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 = q17 TO q41. COMPUTE GrpOrder = 1. COMPUTE VarName = 'A'. LOOP VarOrder = 1 TO 4. . COMPUTE VarValue = A(VarOrder). . XSAVE OUTFILE = UNROLL_A / KEEP = CASE GrpOrder VarOrder VarName VarValue. END LOOP. VECTOR B = q19a TO q81g. COMPUTE GrpOrder = 2. COMPUTE VarName = 'B'. LOOP VarOrder = 1 TO 166. . COMPUTE VarValue = B(VarOrder). . XSAVE OUTFILE = UNROLL_B / KEEP = CASE GrpOrder VarOrder VarName VarValue. END LOOP. VECTOR c = q55 TO q76y. COMPUTE GrpOrder = 3. COMPUTE VarName = 'C'. LOOP VarOrder = 1 TO 31. . COMPUTE VarValue = C(VarOrder). . XSAVE OUTFILE = UNROLL_C / KEEP = CASE GrpOrder VarOrder VarName VarValue. END LOOP. VECTOR D = LADDSCH TO LADDAUS. COMPUTE GrpOrder = 4. COMPUTE VarName = 'D'. LOOP VarOrder = 1 TO 3. . COMPUTE VarValue = D(VarOrder). . XSAVE OUTFILE = UNROLL_D / 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 /FILE=UNROLL_D /BY CASE GrpOrder VarOrder. DATASET NAME Medians. LIST. * III. Take the medians . NUMERIC Median (F4.1). AGGREGATE /OUTFILE =* /BREAK = Case GrpOrder VarName /Median = MEDIAN (VarValue). FORMATS Median (F4.1). LIST. * IV. Combine all four medians into one record . CASESTOVARS /ID = CASE /RENAME GrpOrder = Ord Median = Mdn /INDEX = VarName /SEPARATOR = "" /GROUPBY = VARIABLE . LIST. * V. Finally, combine with the original data . MATCH FILES /FILE='C:\Documents and Settings\amplontz\Desktop\MedianInputFile.sav' /FILE=* /BY CASE /DROP=OrdA OrdB OrdC OrdD. TEMPORARY. STRING SPACE (A4). LIST CASE TO MdnD SPACE. |
At 02:04 AM 4/18/2007, Aude Plontz wrote:
>after you (and thanks so much to Richard and Jon!) helped me having >SPSS version 14 compute ipsative medians (= median for each case, and >not the median for a specified variable), I felt ready to go to the >next step of my analysis... and got lost again. Good! Glad it helped. >What I would like to do using SPSS Version 14: >I would like to have a variable indicating for each case and for each >set of variables (sets A, B, C, and D) how many answers are above the >value indicated in the variables MdnA, MdnB, MdnC, and MdnD >respectively. > >Please see the example below, applied to Set A and the first 2 cases, >the >last column of the table showing which kind of data I would like to >obtain >for each set of variables (SupMdnA, which is the number of answers >above >MdnA): > q17 q18 ENGL q41 MdnA SupMdnA >Case 1 1 1 2 2 2 0 >Case 2 1 2 3 3 3 1 >I started with >. COUNT InfMdnA = q17 TO q41 (LO THRU MdnA) >intending to continue with >. COMPUTE SupMdnA = 3 - InfMdn) >but one can't do that. Right. The range for COUNT has to be specified as constants. But you can do it pretty easily with explicit looping. DO REPEAT is probably the easiest to write. The fanciest code is the LIST commands to make the output look pretty. I'm using the test data as I posted for your first question. SPSS 14 draft output. TEMPORARY. STRING CaseSpce (A60) DataSpce (A04) Median (A07) Bspace (A15) Cspace (A23). LIST CASE CaseSpce A1 TO A3 B1 TO B5 C1 TO C7 DataSpce Median MdnA Bspace MdnB Cspace MdnC. List |-----------------------------|---------------------------| |Output Created |18-APR-2007 11:17:36 | |-----------------------------|---------------------------| 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: Median MdnA Bspace MdnB Cspace MdnC CASE: 06 A1: 2 2 98 1 1 6 7 3 2 98 7 98 4 7 6 Median: 2.0 3.0 6.0 CASE: 07 A1: 3 98 2 4 4 7 4 6 5 98 9 2 8 9 98 Median: 2.5 4.0 8.0 CASE: 08 A1: 98 1 2 1 1 4 7 7 6 6 98 2 1 6 98 Median: 1.5 4.0 6.0 CASE: 09 A1: 1 3 1 3 1 7 7 7 6 8 6 6 5 2 98 Median: 1.0 7.0 6.0 CASE: 10 A1: 1 3 2 5 5 1 1 6 6 8 98 9 98 5 5 Median: 2.0 5.0 6.0 Number of cases read: 10 Number of cases listed: 10 NUMERIC InfMdnA SupMdnA InfMdnB SupMdnB InfMdnC SupMdnC (F3). * 'Cute' way to set a bunch of variables to 0: . RECOD InfMdna TO SupMdnC (ELSE=0). DO REPEAT A = A1 TO A3. . IF A LE MdnA InfMdnA = InfMdnA + 1. . IF A GT MdnA SupMdnA = SupMdnA + 1. END REPEAT. DO REPEAT B = B1 TO B5. . IF B LE MdnB InfMdnB = InfMdnB + 1. . IF B GT MdnB SupMdnB = SupMdnB + 1. END REPEAT. DO REPEAT C = C1 TO C7. . IF C LE MdnC InfMdnC = InfMdnC + 1. . IF C GT MdnC SupMdnC = SupMdnC + 1. END REPEAT. TEMPORARY. STRING CaseSpce (A60) DataSpce (A04) Aspace (A07) Median (A07) Infra (A07) Supra (A07) Bspace (A15) Cspace (A23). LIST CASE CaseSpce A1 TO A3 B1 TO B5 C1 TO C7 DataSpce Median MdnA Bspace MdnB Cspace MdnC Infra InfMdnA Bspace InfMdnB Cspace InfMdnC Supra SupMdnA Bspace SupMdnB Cspace SupMdnC. List |-----------------------------|---------------------------| |Output Created |18-APR-2007 11:17:38 | |-----------------------------|---------------------------| 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: Median MdnA Bspace MdnB Cspace MdnC LINE 4: Infra InfMdnA Bspace InfMdnB Cspace InfMdnC LINE 5: Supra SupMdnA Bspace SupMdnB Cspace SupMdnC CASE: 03 A1: 2 1 2 3 7 5 98 6 3 8 98 7 8 9 98 Median: 2.0 5.5 8.0 CASE: 04 A1: 3 98 3 98 5 1 98 2 9 1 1 98 98 2 9 Median: 3.0 2.0 2.0 CASE: 05 A1: 2 3 3 98 1 7 2 3 98 6 8 8 3 5 5 Median: 3.0 2.5 5.5 CASE: 01 A1: 1 2 3 6 7 4 3 5 6 4 1 98 8 9 6 Median: 2.0 5.0 6.0 Infra: 2 3 4 Supra: 1 2 2 CASE: 02 A1: 3 2 2 7 1 98 7 5 8 9 5 9 1 98 1 Median: 2.0 6.0 6.5 Infra: 2 2 3 Supra: 1 2 3 CASE: 03 A1: 2 1 2 3 7 5 98 6 3 8 98 7 8 9 98 Median: 2.0 5.5 8.0 Infra: 3 2 4 Supra: 0 2 1 CASE: 04 A1: 3 98 3 98 5 1 98 2 9 1 1 98 98 2 9 Median: 3.0 2.0 2.0 Infra: 2 2 3 Supra: 0 1 2 CASE: 05 A1: 2 3 3 98 1 7 2 3 98 6 8 8 3 5 5 Median: 3.0 2.5 5.5 Infra: 3 2 3 Supra: 0 2 3 CASE: 06 A1: 2 2 98 1 1 6 7 3 2 98 7 98 4 7 6 Median: 2.0 3.0 6.0 Infra: 2 3 3 Supra: 0 2 2 CASE: 07 A1: 3 98 2 4 4 7 4 6 5 98 9 2 8 9 98 Median: 2.5 4.0 8.0 Infra: 1 3 3 Supra: 1 2 2 CASE: 08 A1: 98 1 2 1 1 4 7 7 6 6 98 2 1 6 98 Median: 1.5 4.0 6.0 Infra: 1 3 5 Supra: 1 2 0 CASE: 09 A1: 1 3 1 3 1 7 7 7 6 8 6 6 5 2 98 Median: 1.0 7.0 6.0 Infra: 2 5 5 Supra: 1 0 1 CASE: 10 A1: 1 3 2 5 5 1 1 6 6 8 98 9 98 5 5 Median: 2.0 5.0 6.0 Infra: 2 4 3 Supra: 1 1 2 Number of cases read: 10 Number of cases listed: 10 =================== APPENDIX: Test data =================== * ................................................... . * ............ Test data ............ . * Activate the following statements, or run them separately: . . /**/ INCLUDE /*-*/ /**/ 'C:\Documents and Settings\Richard\My Documents' + /*-*/ /**/ '\Technical\spssx-l\Z-2007b' + /*-*/ /**/ '\2007-04-13 PLONTZ - ' + /*-*/ /**/ 'Ipsative median computation with SPSS 14.SPS' /*-*/. . /**/ DATASET NAME WithMedn /*-*/. * SPSSX-L: Included program posted in two versions - . . * . * Date: Fri, 13 Apr 2007 13:52:40 -0400 . * Reply-To: Richard Ristow <[hidden email]> . * Subject: Re: Ipsative median computation with SPSS 14 . * To: [hidden email] . * and . * Date: Sat, 14 Apr 2007 23:54:53 -0400 . * From: Richard Ristow <[hidden email]> . * Subject: Re: Ipsative median computation with SPSS 14 . * To: [hidden email] . * ................................................... . ADD FILES /FILE=WithMedn. |
Free forum by Nabble | Edit this page |