Date: Tue, 6 Nov 2007 09:45:24 -0800
Reply-To: King Douglas <king_d@swbell.net>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: King Douglas <king_d@swbell.net>
Subject: Re: Randomization into 3 groups
In-Reply-To: <5E0F889A8147254F83D0250D0E7CE6C66C130D@DCSH15VX.root.sutterhealth.org>
Content-Type: text/plain; charset=iso-8859-1
Carol,
Here are two nifty solutions, one provided by Jan Spousta, the other by Raynald Levesque and both posted to this list just a few weeks ago.
I'm sure that either will prove useful, given slight modifications.
Regards,
King Douglas
American Airlines Customer Research
http://www.kingdouglas.com/SPSS.HTM
JAN SPOUSTA:
Run the following syntax from a Syntax window (Run -> All) ; suppose you have opened a datafile with 96 rows:
COMPUTE aux_id = $casenum /*to be able to restore the original order of rows*/.
COMPUTE random_number = uniform(1) .
SORT CASES BY random_number (A) .
compute random_number = $casenum /*to convert the random numbers from <0,1> into 1, 2, 3..., N */.
compute random_group = mod(random_number, 3) + 1 /* create 3 groups */.
SORT CASES BY aux_id (A) .
formats random_group aux_id random_number (f6).
var lab random_group "Random group".
Results are in the variable random_group. Hope this helps
Jan
RAYNALD LEVESQUE:
Here is one method:
* Create a sample file for illustration purspoes.
INPUT PROGRAM.
LOOP id=1 TO 96 .
- END CASE.
END LOOP .
END FILE.
END INPUT PROGRAM.
* Do the job.
COMPUTE draw=UNIFORM(1).
SORT CASES BY draw.
RANK VARIABLES=draw /NTILES(3) INTO group .
Regards
--
Raynald Levesque
www.spsstools.net
"Parise, Carol A." <PariseC@sutterhealth.org> wrote: Hi all,
Does anyone have some nifty code to tell SPSS to do the following:
1. Create a variable called ID and assign ID numbers 1-315.
2. Create a variable called Group and randomly assign a 1, 2, or 3 to each of the 315 IDs so that 105 cases get a 1, 105, get a 2 and 105 get a 3.
I've used UNIFORM to randomly assign a list to either a 1 or 0 and i could easily create these variables and mannually do this.
However, seeing the syntax to do this would be valuable for some other tasks like this.
Thanks
Carol
=====================
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
=====================
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