Hi,
I'm trying to insert an index in my new data sample. I would like to give a unik Id to each case in a variable. ex. v1 id lon 1 lon 1 lon 1 ska 2 ska 2 sto 3 sto 3 xxx 4 xxx 4 how can i create id? thanks |
Administrator
|
Look up the RANK command, and rank on v1. Notice that there are several ways to deal with ties.
--
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 DEBOER
Read up on
transform --> auto-recode in the manual. Mark Webb Line +27 (21) 786 4379 Cell +27 (72) 199 1000 Fax to email +27 (86) 5513075 Skype webbmark Email [hidden email] On 2011/07/11 09:22 AM, DEBOER wrote: > Hi, > I'm trying to insert an index in my new data sample. I would like to give a > unik Id to each case in a variable. > > ex. > > v1 id > lon 1 > lon 1 > lon 1 > ska 2 > ska 2 > sto 3 > sto 3 > xxx 4 > xxx 4 > > how can i create id? > > thanks > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/casenum-tp4574132p4574132.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > 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 Bruce Weaver
V1 is a string ;-)
-- Simplest way is a 2 liner.. IF (V1 NE LAG(V1)) #ID=#ID+1. COMPUTE ID=#ID. * If you wish to achieve deeper comprehension of how/why this works consult the manual and refer to SCRATCH variables. --
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?" |
Administrator
|
Oops...I forgot that RANK only works on numeric variables. If one just wants ID numbers from 1 to N though, I think Mark's AUTORECODE method is even simpler than the LAG method. It's a one-liner, and remains so even if the cases are not sorted on V1.
new file. dataset close all. data list list / v1 (a3) . begin data lon lon ska ska lon sto xxx sto xxx end data. AUTORECODE VARIABLES=v1 / INTO ID1 . * Sort needed for LAG method. sort cases by v1. IF (V1 NE LAG(V1)) #ID=#ID+1. COMPUTE ID2=#ID. list.
--
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/). |
Administrator
|
Point taken and well understood (my assumption was to build the values based on the sequence of cases in the file). OTOH, if one wishes to build IDs to identify blocks of contiguous cases based on another variable irrespective of the values of other cases in the file, AUTORECODE will impose it's own ID values based on the sort order of these values.
var AR LG aaa 1 1 aaa 1 1 ccc 4 2 ccc 4 2 bbb 3 3 bbb 3 3 xxx 6 4 uuu 5 5 uuu 5 5 aa2 2 6
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?" |
Free forum by Nabble | Edit this page |