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 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 28 Sep 2005 23:31:13 -0400
Reply-To:     Richard Ristow <wrristow@mindspring.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Richard Ristow <wrristow@mindspring.com>
Subject:      Re: Random number  without  replacement
Comments: To: Abdus Salam <mou_salam@yahoo.com>
In-Reply-To:  <20050928142647.94177.qmail@web31103.mail.mud.yahoo.com>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 10:26 AM 9/28/2005, Abdus Salam wrote:

>I have a data which contain's Iran's area code and exchange number >i.e. >Suppose area code:771 and exchange code:252,253,222 > >Now my problem is: I want to generate 60 - (4 digit random number's >) under this exchange code without replacement. Is it possible?

It's possible, and not particularly difficult. There are several methods. Below is one of the fancier, known as the "K/N" method (you'll see why, in the code). It's probably fancier than is needed here, but it does the job neatly, and generates the sample in numerical order.

I've assumed that 0000 is not an acceptable number, and I've generated 10 numbers for each exchange. Sampling is "without replacement" only within an area code and exchange; I assume that's what you wanted. The following is tested; SPSS draft output:

"Initialize random number generator": Two steps recommended, A. Set seed from a source of non-systematic numbers. Don't use the same seed twice B. Generate and discard 100 random numbers, after seeding.

List Notes |---------------------------|-----------------------| |Output Created |28 Sep 05 23:21:57 | |---------------------------|-----------------------| AREACODE EXCHANGE

771 252 771 253 771 222

Number of cases read: 3 Number of cases listed: 3

* Initialize random-number generator: . DO IF $CASENUM = 1. * Seed: trailing four digits of second number on . * p. 769 of Providence, RI, telephone book for 2005. . . SET SEED = 1305. * "Throw away" 100 variates, to bypass anomalous . * variates that may occur immediately post-seeding . - LOOP # = 1 TO 100. . COMPUTE #DISCARD = RV.UNIFORM(0,1). - END LOOP. END IF.

COMPUTE #K = 10 /* Desired sample size */. COMPUTE #N = 9999 /* Population size; must be exact */.

NUMERIC NUMBER (N4). LOOP NUMBER = 1 TO 9999. . DO IF RV.UNIFORM(0,1) LE #K/#N. . XSAVE OUTFILE=SAMPLE. . COMPUTE #K = #K - 1. . END IF. . COMPUTE #N = #N - 1. END LOOP. EXECUTE. GET FILE=SAMPLE. LIST.

List Notes |---------------------------|-----------------------| |Output Created |28 Sep 05 23:22:00 | |---------------------------|-----------------------| AREACODE EXCHANGE NUMBER

771 252 0787 771 252 0819 771 252 0849 771 252 1591 771 252 5511 771 252 6729 771 252 7031 771 252 7535 771 252 7601 771 252 8976 771 253 0375 771 253 1310 771 253 1756 771 253 2405 771 253 2641 771 253 5201 771 253 7170 771 253 7662 771 253 9074 771 253 9572 771 222 0003 771 222 0261 771 222 1904 771 222 2322 771 222 4317 771 222 6632 771 222 6969 771 222 7526 771 222 9424 771 222 9503

Number of cases read: 30 Number of cases listed: 30


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