|
Hi All,
I have a data set that contains 80 string variables (test questions; Q1 to Q80). The first record in the data set is the answer key. What I need to do in order to run a point-bi correlation is recode the string data to 1s and 0s for all the records based on the first casenum. For example, I want to recode every instance If casenum1 = 'A' for q1 to q80 then all other records get recoded A=1 else=0. ID Score Q1 Q2 Q3 Q4 Q5 Q6... Key 80.00 A C E D A B 593354404 66.00 A B E C A B 068624443 49.00 B A A D A A Below is the syntax I use to recode each variable one at a time but I'm looking for syntax that will allow me to perform a recode for **all** variables more efficiently. RECODE q1 ('A'='1') (ELSE='0') . EXECUTE . Any help is appreciated. Regards, Kurt Wilkening General Manager Recruiting, Testing, and Certification Hillsborough County Civil Service Board 601 E. Kennedy Blvd., 17th Floor Tampa, Florida 33602 (813) 274-6764 (Direct) ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
Hi Kurt,
Assuming that your target variables are contiguous: DO IF $casenum = 1. + RECODE q1 to q80 ('A'='1') (ELSE='0') . END IF. I don't quite understand why you would want to use a DO IF in this way, but this is how I understood your post. Cheers!! Albert-Jan --- On Thu, 11/6/08, Kurt Wilkening <[hidden email]> wrote: > From: Kurt Wilkening <[hidden email]> > Subject: Recode Syntax > To: [hidden email] > Date: Thursday, November 6, 2008, 4:15 PM > Hi All, > > I have a data set that contains 80 string variables (test > questions; Q1 to > Q80). The first record in the data set is the answer key. > What I need to > do in order to run a point-bi correlation is recode the > string data to 1s > and 0s for all the records based on the first casenum. > > For example, I want to recode every instance If casenum1 = > 'A' for q1 to > q80 then all other records get recoded A=1 else=0. > > ID Score Q1 Q2 Q3 Q4 Q5 > Q6... > Key 80.00 A C E D A B > 593354404 66.00 A B E C A B > 068624443 49.00 B A A D A A > > Below is the syntax I use to recode each variable one at a > time but I'm > looking for syntax that will allow me to perform a recode > for **all** > variables more efficiently. > > RECODE > q1 ('A'='1') (ELSE='0') . > EXECUTE . > > > Any help is appreciated. > > Regards, > > Kurt Wilkening > General Manager > Recruiting, Testing, and Certification > Hillsborough County Civil Service Board > 601 E. Kennedy Blvd., 17th Floor > Tampa, Florida 33602 > (813) 274-6764 (Direct) > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body > text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the > command > INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Kurt Wilkening
Kurt,
Here's a different approach to using a scoring key. This would be a bit easier to deal with if you converted the strings to numbers before you started, but as you can see it still works fine with the strings. You just need to put your "key" in the 'correct=' line within the do repeat line instead of the first line of your dataset. This example uses temporary variables (#s01 to #s10) to use in the total score calculation, but you could remove the '#' and store the variables. This would be useful if you wanted to do any item-level calculations. DATA LIST LIST /Q01 (A8) Q02 (A8) Q03 (A8) Q04 (A8) Q05 (A8) Q06 (A8) Q07 (A8) Q08 (A8) Q09 (A8) Q10 (A8). BEGIN DATA B D C A A D B A B C B D C C A D B A B B B D C A A D B A B C B D B C A D B A B C B D C A A D B D B C B D C A A D C A B C A B C A A D B C B C B D C A D D B C B C B D C C D D B A B C B D C A D D B A B D B D B A A D B A B C B D C A A D B A D C B D A A A D D C D C A B A A A D B A D C B D C A A D B A B D B D C A A D B A B C B D C A A D B A B C B D C A A D B A B C B D C A A D B A B C B D C A A D A A B C END DATA. do repeat resp=q01 to q10 /correct= 'B' 'D' 'C' 'A' 'A' 'D' 'B' 'A' 'B' 'C' /score=#s01 to #s10. compute score=(resp=correct). end repeat. COMPUTE TOTALSCORE=SUM(#S01 TO #S10). DES TOTALSCORE. --- On Thu, 11/6/08, Kurt Wilkening <[hidden email]> wrote: From: Kurt Wilkening <[hidden email]> Subject: Recode Syntax To: [hidden email] Date: Thursday, November 6, 2008, 10:15 AM Hi All, I have a data set that contains 80 string variables (test questions; Q1 to Q80). The first record in the data set is the answer key. What I need to do in order to run a point-bi correlation is recode the string data to 1s and 0s for all the records based on the first casenum. For example, I want to recode every instance If casenum1 = 'A' for q1 to q80 then all other records get recoded A=1 else=0. ID Score Q1 Q2 Q3 Q4 Q5 Q6... Key 80.00 A C E D A B 593354404 66.00 A B E C A B 068624443 49.00 B A A D A A Below is the syntax I use to recode each variable one at a time but I'm looking for syntax that will allow me to perform a recode for **all** variables more efficiently. RECODE q1 ('A'='1') (ELSE='0') . EXECUTE . Any help is appreciated. Regards, Kurt Wilkening General Manager Recruiting, Testing, and Certification Hillsborough County Civil Service Board 601 E. Kennedy Blvd., 17th Floor Tampa, Florida 33602 (813) 274-6764 (Direct) ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ====================To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Albert-Jan Roskam
Hi Albert,
Not sure I understand your Do IF statement. In my example from the initial email, I want to recode all cases column-wise based on whether the data contained in variables Q1 to Q80 equal whats in casenum 1. If subsequent cases to casenum1 contain variable data identical to the key (casenum 1) then that data gets recoded into a 1, all else a 0. Your syntax would end up recoding all the data in casenum 1 ACROSS variables q1 to q80. >>> Albert-jan Roskam <[hidden email]> 11/6/2008 12:26 PM >>> Hi Kurt, Assuming that your target variables are contiguous: DO IF $casenum = 1. + RECODE q1 to q80 ('A'='1') (ELSE='0') . END IF. I don't quite understand why you would want to use a DO IF in this way, but this is how I understood your post. Cheers!! Albert-Jan --- On Thu, 11/6/08, Kurt Wilkening <[hidden email]> wrote: > From: Kurt Wilkening <[hidden email]> > Subject: Recode Syntax > To: [hidden email] > Date: Thursday, November 6, 2008, 4:15 PM > Hi All, > > I have a data set that contains 80 string variables (test > questions; Q1 to > Q80). The first record in the data set is the answer key. > What I need to > do in order to run a point-bi correlation is recode the > string data to 1s > and 0s for all the records based on the first casenum. > > For example, I want to recode every instance If casenum1 = > 'A' for q1 to > q80 then all other records get recoded A=1 else=0. > > ID Score Q1 Q2 Q3 Q4 Q5 > Q6... > Key 80.00 A C E D A B > 593354404 66.00 A B E C A B > 068624443 49.00 B A A D A A > > Below is the syntax I use to recode each variable one at a > time but I'm > looking for syntax that will allow me to perform a recode > for **all** > variables more efficiently. > > RECODE > q1 ('A'='1') (ELSE='0') . > EXECUTE . > > > Any help is appreciated. > > Regards, > > Kurt Wilkening > General Manager > Recruiting, Testing, and Certification > Hillsborough County Civil Service Board > 601 E. Kennedy Blvd., 17th Floor > Tampa, Florida 33602 > (813) 274-6764 (Direct) > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body > text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the > command > INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Kurt Wilkening
At 10:15 AM 11/6/2008, Kurt Wilkening wrote:
>I have a data set that contains 80 string variables (test questions; >Q1 to Q80). The first record in the data set is the answer key. |-----------------------------|---------------------------| |Output Created |09-NOV-2008 02:42:46 | |-----------------------------|---------------------------| [TestData] ID Score Q1 Q2 Q3 Q4 Q5 Q6 Key 80.00 A C E D A B 593354404 66.00 A B E C A B 068624443 49.00 B A A D A A Number of cases read: 3 Number of cases listed: 3 >I need to recode the string data to 1s and 0s for all the records >based on the first casenum. For example, if casenum1 = 'A' for [any >of] q1 to q80 then [that question in] all other records gets recoded >A=1 else=0: Below are two solutions (they don't use RECODE, which isn't suitable for this problem): . I. Recode variables Q1, Q2, ... to '0' or '1', as you specified. But that probably won't work for you, since you will need numeric values for the correlations. (Giving a string variable a value like '1' doesn't make it a number.) So, instead, . II. Recode Q1, Q2, ... to separate numeric variables. The following code, for both solutions, is tested: * I. Recode, per the specification in the posting ............ . DATASET ACTIVATE TestData WINDOW=FRONT. DATASET COPY Recode1. DATASET ACTIVATE Recode1 WINDOW=FRONT. * Scratch variables, to hold the key values ..................... . . STRING #Key1 TO #Key6 (A1). DO IF ID EQ 'Key'. *..Save key values in scratch variables ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6. . COMPUTE KeyVal = Datum. . END REPEAT. ELSE. *..Compare current values to key values ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6. . DO IF KeyVal EQ Datum. . COMPUTE Datum = '1'. . ELSE. . COMPUTE Datum = '0'. . END IF. . END REPEAT. END IF. LIST. |-----------------------------|---------------------------| |Output Created |09-NOV-2008 03:09:06 | |-----------------------------|---------------------------| [Recode1] ID Score Q1 Q2 Q3 Q4 Q5 Q6 Key 80.00 A C E D A B 593354404 66.00 1 0 1 0 1 1 068624443 49.00 0 0 0 1 1 0 Number of cases read: 3 Number of cases listed: 3 * II. But you probably need numeric recoded variables: ............ . DATASET ACTIVATE TestData WINDOW=FRONT. DATASET COPY Recode2. DATASET ACTIVATE Recode2 WINDOW=FRONT. * Scratch variables, to hold the key values ..................... . . STRING #Key1 TO #Key6 (A1). * Numeric form of the recoded variables ..................... . . NUMERIC NQ1 TO NQ6 (F2). DO IF ID EQ 'Key'. *..Save key values in scratch variables ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6. . COMPUTE KeyVal = Datum. . END REPEAT. ELSE. *..Compare current values to key values ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6 /Number = NQ1 TO NQ6. . DO IF KeyVal EQ Datum. . COMPUTE Number = 1. . ELSE. . COMPUTE Number = 0. . END IF. . END REPEAT. END IF. LIST. |-----------------------------|---------------------------| |Output Created |09-NOV-2008 03:09:08 | |-----------------------------|---------------------------| ID Score Q1 Q2 Q3 Q4 Q5 Q6 NQ1 NQ2 NQ3 NQ4 NQ5 NQ6 Key 80.00 A C E D A B . . . . . . 593354404 66.00 A B E C A B 1 0 1 0 1 1 068624443 49.00 B A A D A A 0 0 0 1 1 0 Number of cases read: 3 Number of cases listed: 3 ============================= APPENDIX: Test data, and code ============================= * C:\Documents and Settings\Richard\My Documents . * \Technical\spssx-l\Z-2008d . * \2008-11-06 Wilkening - Recode Syntax.SPS . * In response to posting . * Date: Thu, 6 Nov 2008 10:15:37 -0500 . * From: Kurt Wilkening <[hidden email]> . * Subject: Recode Syntax . * To: [hidden email] . * "The first record in the data set is the answer key. I need to . * recode the string data to 1s and 0s for all the records based on . * the first casenum. . * . * For example, if casenum1 = 'A' for q1 to q80 then all other . * records get recoded A=1 else=0." . * ................................................................. . * ................. Test data, from posting ................... . DATA LIST LIST / ID Score Q1 Q2 Q3 Q4 Q5 Q6 (A9, F6.2, 6A1). BEGIN DATA Key 80.00 A C E D A B 593354404 66.00 A B E C A B 068624443 49.00 B A A D A A END DATA. DATASET NAME TestData WINDOW=FRONT. LIST. * ................................................................. . * ................. Code ..................... . * I. Recode, per the specification in the posting ............ . DATASET ACTIVATE TestData WINDOW=FRONT. DATASET COPY Recode1. DATASET ACTIVATE Recode1 WINDOW=FRONT. * Scratch variables, to hold the key values ..................... . . STRING #Key1 TO #Key6 (A1). DO IF ID EQ 'Key'. *..Save key values in scratch variables ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6. . COMPUTE KeyVal = Datum. . END REPEAT. ELSE. *..Compare current values to key values ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6. . DO IF KeyVal EQ Datum. . COMPUTE Datum = '1'. . ELSE. . COMPUTE Datum = '0'. . END IF. . END REPEAT. END IF. LIST. * II. But you probably need numeric recoded variables: ............ . DATASET ACTIVATE TestData WINDOW=FRONT. DATASET COPY Recode2. DATASET ACTIVATE Recode2 WINDOW=FRONT. * Scratch variables, to hold the key values ..................... . . STRING #Key1 TO #Key6 (A1). * Numeric form of the recoded variables ..................... . . NUMERIC NQ1 TO NQ6 (F2). DO IF ID EQ 'Key'. *..Save key values in scratch variables ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6. . COMPUTE KeyVal = Datum. . END REPEAT. ELSE. *..Compare current values to key values ..................... . . DO REPEAT Datum = Q1 TO Q6 /KeyVal = #Key1 TO #Key6 /Number = NQ1 TO NQ6. . DO IF KeyVal EQ Datum. . COMPUTE Number = 1. . ELSE. . COMPUTE Number = 0. . END IF. . END REPEAT. END IF. LIST. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
| Free forum by Nabble | Edit this page |
