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 (April 1999)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 29 Apr 1999 08:47:02 -0500
Reply-To:   "Bell, Roberta" <rhbell@INDIANA.EDU>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From:   "Bell, Roberta" <rhbell@INDIANA.EDU>
Subject:   Re: random sampling
Comments:   To: Raynald Levesque <rlevesque@videotron.ca>
Content-Type:   text/plain; charset="iso-8859-1"

Thank you all for your contributions to my problem. Between all the good advice I got I'm sure I'll get it figured out.

Many thanks, Roberta

> -----Original Message----- > From: Raynald Levesque [SMTP:rlevesque@videotron.ca] > Sent: Wednesday, April 28, 1999 8:28 PM > To: SPSS mailing list; Bell, Roberta > Subject: Re: random sampling > > Hi Roberta! > > The following syntax will get 50 samples of approximately x% of the 4000 > cases, sum the values the money variable contained in each sample and save > the 50 results in a file called sample.sav. The number of the sample (1 > through 50) is also saved. The x% and the number of samples are arguments > in > the macro call and are thus easy to change. > > Before running the script, you must ensure that a sample.sav file already > exists. The sample file must contain the 3 numeric variables filter_$, > money > and sample. You may enter arbitrary data for each of these 3 variables or > enter no data at all. The first thing the syntax does is to erase the > cases > in that file. Only the variables names are used. I am sorry for this > manual > step, but I did not think it was worth it to do this automatically. > > The syntax uses the syntax pasted form the window obtained through the > following sequence from menu: Data->Select Cases->Random sample of > cases->Approximately. > To implement the "Exactly" option would be a little bit more difficult. > Please advise if this is what you required. > > The syntax is as follows: > > > * -------------------DEFINE > MACRO ---------------------------------------------. > DEFINE !SAMPLE( !POS !TOKENS(1) > /!POS !TOKENS(1)). > > * This block of instructions empties the existing sample file. > GET > FILE='C:\Program Files\SPSS\test\sample.sav'. > EXECUTE . > FILTER OFF. > USE ALL. > SELECT IF(money<0). > EXECUTE . > SAVE OUTFILE='C:\Program Files\SPSS\test\sample.sav' > /COMPRESSED. > > > !DO !Count = 1 !TO !2. > > GET > FILE='C:\Program Files\SPSS\test\money.sav'. > EXECUTE . > > USE ALL. > COMPUTE filter_$=(uniform(1)<=!1). > FILTER BY filter_$. > EXECUTE . > > COMPUTE sample=!Count. > > AGGREGATE > /OUTFILE=* > /BREAK=filter_$ > /money = SUM(money) /sample=FIRST(sample). > > ADD FILES /FILE=* > /FILE='C:\Program Files\SPSS\test\sample.sav'. > > SAVE OUTFILE='C:\Program Files\SPSS\test\sample.sav' > /COMPRESSED. > > !DOEND. > > !ENDDEFINE. > * ----------------END OF > MACRO ----------------------------------------------. > > * Call macro (parameters are size of sample (here 5%) and number of > samples > (here 10) > > !SAMPLE .05 10. > > > > I hope this helps. > > Regards > > Raynald Levesque rlevesque@videotron.ca > > ----- Original Message ----- > From: Bell, Roberta <rhbell@INDIANA.EDU> > Newsgroups: bit.listserv.spssx-l > To: <SPSSX-L@UGA.CC.UGA.EDU> > Sent: Wednesday, April 28, 1999 2:06 PM > Subject: FW: random sampling > > > > > I'm sorry. I wrote that in a hurry. > > > > > > I have a file with about 4,000 individuals and one variable, say > money. > I > > > would like > > > to sample a percent of them and sum their values on the money > variable. > I > > > would like > > > to sample this 50 times (or more) so that I get 50 sums for the entire > > > group. I know > > > that SPSS cannot store group sums for individual cases, so I figure it > > > needs to be > > > written to another file. Does that make sense? Can you help? > > > > > > Thanks, > > > Roberta > > > > > > rhbell@indiana.edu > > > > > > -----Original Message----- > > > From: Shailendra Dobson [SMTP:s.dobson@marketprobe.ca] > > > Sent: Wednesday, April 28, 1999 12:39 PM > > > To: Bell, Roberta > > > Subject: Re: random sampling > > > > > > You might rephrase your question. Sorry I don't know the answer. > > > -----Original Message----- > > > From: Bell, Roberta <rhbell@INDIANA.EDU> > > > Newsgroups: bit.listserv.spssx-l > > > To: SPSSX-L@UGA.CC.UGA.EDU <SPSSX-L@UGA.CC.UGA.EDU> > > > Date: Wednesday, April 28, 1999 1:31 PM > > > Subject: random sampling > > > > > > > > > >> I am hoping someone can help. I would like to produce a number of > > > random > > > >> samples (say 50 samples), sum a variable for each sample and save > each > > > sum > > > >> as a field in another file. How would I write the code? > > > >> > > > >> Thank you so much, > > > >> > > > >> Roberta > > > >> > > > >> please cc response to rhbell@indiana.edu > > > >


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