LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2010)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 27 Sep 2010 13:41:24 -0700
Reply-To:   Bruce Weaver <bruce.weaver@hotmail.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Bruce Weaver <bruce.weaver@hotmail.com>
Subject:   Re: generating random (not consecutive) identification numbers
In-Reply-To:   <OFC0EA4A9D.39CC0C1C-ON862577AB.006CB18A-862577AB.006E7A15@us.ibm.com>
Content-Type:   text/plain; charset=us-ascii

Agreed. What I was thinking, but didn't say explicitly was that one would need a large range of values; and that to get rid of the decimals, one could then multiply by some large multiple of 10 before truncating or rounding. Something like this, for example:

new file. dataset close all.

* Generate a file with lots of cases.

INPUT PROGRAM. LOOP case=1 TO 10000. END CASE. END LOOP. END FILE. END INPUT PROGRAM. EXECUTE.

* Compute a random ID number with a large range, and truncate. compute id = trunc(rv.uniform(1, 10**10)). exe.

* Use the NU function in AGGREGATE to obtain the * number of cases for each unique ID number.

AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=id /n_ID=Nu.

freq n_ID.

* If there are no duplicate IDs, the frequency * table should show only a value of 1 with the * frequency count being the number of cases in * the file.

I've run this a few times, and have not yet to see any duplicate IDs.

Cheers, Bruce

Rick Oliver wrote: > > Using this method, the unique IDs will contain decimals. If you truncate > or round the values, they may no longer be unique, unless the specified > range of values is considerably larger than the number of cases. > > > > From: > Bruce Weaver <bruce.weaver@hotmail.com> > To: > SPSSX-L@LISTSERV.UGA.EDU > Date: > 09/27/2010 02:34 PM > Subject: > Re: generating random (not consecutive) identification numbers > Sent by: > "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> > > > > Debbie Hahs-Vaughn wrote: >> >> I have used COMPUTE ID=$CASENUM to generate consecutive identification >> numbers. However how can I generate identification numbers that are not >> consecutive but just purely random? I am trying to avoid having numbers >> that are only one digit difference in the ID so that there is less room >> for >> error in what we are trying to do. Thanks! >> >> > > Instead of $casenum, use one of the random variable functions, such as > RV.UNIFORM. From the Help: > > RV.UNIFORM. RV.UNIFORM(min, max). Numeric. Returns a random value from a > uniform distribution with specified minimum and maximum. See also the > UNIFORM function. > > If you want to obtain the same IDs every time you run the syntax, set the > value of the seed first (via the SET command). Here's the description of > the seed from the Help: > > "Initialization value for MC random number generator. The value must be a > positive integer that is less than 2,000,000,000 or the keyword RANDOM, > which randomly sets the initialization value. The default is 2,000,000." > > And finally, assuming you have one row per ID, you'll want to follow up > with a check for duplicate IDs. It's not very likely, but could happen. > > > > ----- > -- > Bruce Weaver > bweaver@lakeheadu.ca > http://sites.google.com/a/lakeheadu.ca/bweaver/ > > "When all else fails, RTFM." > > NOTE: My Hotmail account is not monitored regularly. > To send me an e-mail, please use the address shown above. > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/generating-random-not-consecutive-identification-numbers-tp2855693p2855817.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@LISTSERV.UGA.EDU (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 > > > >

----- -- Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.

-- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/generating-random-not-consecutive-identification-numbers-tp2855693p2855887.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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


Back to: Top of message | Previous page | Main SPSSX-L page