Dear SPSS Gurus,
I need your help in getting simplified SPSS syntax to expedite two operations. I am using SPSS 20.0.0.2. First, I need to form adjacent pairs of cases into new groups, and, second, I need to assign either a 1 or a 2 to each member of the pair in a given group. To handle the first operation, I am using a variable named NEW_ID01, and I have assigned each case a number in sequence from 1 to 450. I am thinking that I can form the pairs through a recode statement such as the following: RECODE NEW_ID01 (1,2=1)(3,4=2)(5,6=3) ... (449,450=225) INTO PAIRS01. However, this procedure is quite laborious when the number of cases exceeds 1,000 or more in other datasets. Thus, I welcome any suggestions for automating this operation. Second, I need to create a new variable to assign a 1 or 2 to each member of each pair. Thus, when PAIRS01=1, then NEW_ID02 becomes 1 for the case whose NEW_ID01=1 and 2 for case whose NEW_ID01=2; when PAIRS01=2, then NEW_ID02 becomes 1 for the case whose NEW_ID01=3 and 2 for the case whose NEW_ID01=4, and so on. In other words, within each pair, each case is numbered through a new variable as either 1 or 2. I could perform this operation manually in the data entry sheet by entering either 1 or 2 next to the members of each pair, but I would prefer to have a reliable syntax procedure to automate this endeavor. I normally get responses through a daily digest; however, because I am working on this problem today, I welcome a response not only to the list but also to my home email address which is on the CC: line. Thank you. David ===================== 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 |
Jaspal is on vacation from July 2, 2013 to July 5, 2013 inclusive. Please contact Shabari Phadkar at 416-327-4856 for immediate assistance. Thanks.
===================== 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 David B. Nolle-2
I think this is what you want. I assuming that the cases to be paired are adjacent to each other and such that the first case in the pair is going to be '1' and the second case is going to be '2'.
Compute pairs01=1+trunc((new_id01-1)/2). Compute seq=1+mod((new_id01+1),2). Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David B. Nolle Sent: Friday, June 28, 2013 4:26 PM To: [hidden email] Subject: Pairing Consecutive Cases and Assigning New Numbers to Each Member of Each of the Resulting Pairs Dear SPSS Gurus, I need your help in getting simplified SPSS syntax to expedite two operations. I am using SPSS 20.0.0.2. First, I need to form adjacent pairs of cases into new groups, and, second, I need to assign either a 1 or a 2 to each member of the pair in a given group. To handle the first operation, I am using a variable named NEW_ID01, and I have assigned each case a number in sequence from 1 to 450. I am thinking that I can form the pairs through a recode statement such as the following: RECODE NEW_ID01 (1,2=1)(3,4=2)(5,6=3) ... (449,450=225) INTO PAIRS01. However, this procedure is quite laborious when the number of cases exceeds 1,000 or more in other datasets. Thus, I welcome any suggestions for automating this operation. Second, I need to create a new variable to assign a 1 or 2 to each member of each pair. Thus, when PAIRS01=1, then NEW_ID02 becomes 1 for the case whose NEW_ID01=1 and 2 for case whose NEW_ID01=2; when PAIRS01=2, then NEW_ID02 becomes 1 for the case whose NEW_ID01=3 and 2 for the case whose NEW_ID01=4, and so on. In other words, within each pair, each case is numbered through a new variable as either 1 or 2. I could perform this operation manually in the data entry sheet by entering either 1 or 2 next to the members of each pair, but I would prefer to have a reliable syntax procedure to automate this endeavor. I normally get responses through a daily digest; however, because I am working on this problem today, I welcome a response not only to the list but also to my home email address which is on the CC: line. Thank you. David ===================== 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 |
Administrator
|
In reply to this post by David B. Nolle-2
I don't have SPSS on this machine, so the following is untested. It assumes the file is sorted on NEW_ID01.
COMPUTE NEW_ID02 = MOD(NEW_ID01,2). * NEW_ID02 will have values of 1 and 0 rather than 1 and 2 at this point. COMPUTE PAIRS01 = $casenum EQ 1. IF ($casenum GT 1) PAIRS01 = LAG(PAIRS01) + NEW_ID02*1. RECODE NEW_ID02 (0=2) (ELSE=copy). DESCRIPTIVES NEW_ID02 PAIRS01. HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Maguin, Eugene
Hi Gene,
Your two lines of code were the answer! Thank you for your very prompt and helpful response. David ----- Original Message ----- From: "Maguin, Eugene" <[hidden email]> To: "'David B. Nolle'" <[hidden email]>; <[hidden email]> Sent: Friday, June 28, 2013 4:36 PM Subject: RE: Pairing Consecutive Cases and Assigning New Numbers to Each Member of Each of the Resulting Pairs I think this is what you want. I assuming that the cases to be paired are adjacent to each other and such that the first case in the pair is going to be '1' and the second case is going to be '2'. Compute pairs01=1+trunc((new_id01-1)/2). Compute seq=1+mod((new_id01+1),2). Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David B. Nolle Sent: Friday, June 28, 2013 4:26 PM To: [hidden email] Subject: Pairing Consecutive Cases and Assigning New Numbers to Each Member of Each of the Resulting Pairs Dear SPSS Gurus, I need your help in getting simplified SPSS syntax to expedite two operations. I am using SPSS 20.0.0.2. First, I need to form adjacent pairs of cases into new groups, and, second, I need to assign either a 1 or a 2 to each member of the pair in a given group. To handle the first operation, I am using a variable named NEW_ID01, and I have assigned each case a number in sequence from 1 to 450. I am thinking that I can form the pairs through a recode statement such as the following: RECODE NEW_ID01 (1,2=1)(3,4=2)(5,6=3) ... (449,450=225) INTO PAIRS01. However, this procedure is quite laborious when the number of cases exceeds 1,000 or more in other datasets. Thus, I welcome any suggestions for automating this operation. Second, I need to create a new variable to assign a 1 or 2 to each member of each pair. Thus, when PAIRS01=1, then NEW_ID02 becomes 1 for the case whose NEW_ID01=1 and 2 for case whose NEW_ID01=2; when PAIRS01=2, then NEW_ID02 becomes 1 for the case whose NEW_ID01=3 and 2 for the case whose NEW_ID01=4, and so on. In other words, within each pair, each case is numbered through a new variable as either 1 or 2. I could perform this operation manually in the data entry sheet by entering either 1 or 2 next to the members of each pair, but I would prefer to have a reliable syntax procedure to automate this endeavor. I normally get responses through a daily digest; however, because I am working on this problem today, I welcome a response not only to the list but also to my home email address which is on the CC: line. Thank you. David ===================== 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 |
Administrator
|
In reply to this post by Maguin, Eugene
This makes my head throb a bit less than Gene's code ;-)
COMPUTE X=MOD(new_id01,2) . COMPUTE PAIR=SUM(X EQ 1,LAG(PAIR)). RECODE X(0=2)(ELSE=COPY). EXECUTE.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Maguin, Eugene
Gene, Bruce, and David M.,
Thank you for taking the time to respond to my request. I am pleased to report that all three different syntax solutions converged on the same results. I have successfully used the results to form collapsed replicates for a jackknife procedure for sampling error variance estimation in a sample. Again, I continue to be greatly impressed with the responsiveness and expertise which are exhibited by the members of this list (SPSS-L). David N. ===================== 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 |