1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
** Valentim R. Alferes (University of Coimbra, Portugal)
** valferes@fpce.uc.pt

* This syntax does random assignment of units (subjects) to 
* experimental treatments and can be used for Completely Randomized
* Designs (n per treatment equal or unequal).

* For Randomized Block Designs (Simple or Generalized) and also for 
* Completely Randomized Designs with equal n per treatment, you can use the
* syntax job posted in:
http://pages.infinit.net/rlevesqu/Syntax/BlockDesign/RandomAssignmentOfUnitsToExpTreatments.txt

* In the example, we have 3 treatments (A, B, and C) with 8, 9, and 6 
* subjects.


DATA LIST LIST /TREAT(A20) N_TREAT(F8.0).
* Enter treatment names and number of subjects per treatment.
BEGIN DATA
A 8
B 9
C 6
END DATA.

LOOP CASES=1 TO N_TREAT.
XSAVE OUTFILE=OUTF1/KEEP=TREAT.
END LOOP.
EXECUTE.
GET FILE=OUTF1.

SET SEED RANDOM.
COMPUTE RANDOM=RV.UNIFORM(0,1).
SORT CASES BY RANDOM(A).
RANK VARIABLES=RANDOM(A).
COMPUTE ID=RRANDOM.
FORMATS ID(F8.0).
LIST ID TREAT.
SORT CASES BY TREAT (A) ID (A).
SPLIT FILE SEPARATE BY TREAT.
LIST ID.




* Note 1:
* You can enter any treatment names (up to 20 characters). For example,
* in a Completely Randomized Factorial Design with 4 treatments and 15
* subjects per treatment:
*    […]
*    BEGIN DATA
*    A1B1 15
*    A1B2 15
*    A2B1 15
*    A2B2 15
*    END DATA.
*    […].



* Note 2:
* If you have N subjects and p treatments and you want SPSS randomly
* assigns treatments and determines the number of subjects per treatment,
* run the following syntax.
* Example: 40 subjects and 6 treatments (A, B, C, D, E and F).


DATA LIST FREE /TREAT(A20).
* Enter treatments names (A, B, C, D, E and F in the example).
BEGIN DATA
A B C D E F
END DATA.
COMPUTE TREATM=$CASENUM.
SAVE OUTFILE=OUTF1.

INPUT PROGRAM.
* Enter N (total number of cases: 40 in the example).
LOOP N_CASES=1 TO 40.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.

* Enter number of treatments (6 in the example).
COMPUTE N_TREAT=6.
SET SEED RANDOM.
COMPUTE LIM=N_TREAT+.5.
COMPUTE RANDOM1 = RV.UNIFORM(0.5,LIM).
COMPUTE TREATM=RND (RANDOM1).
SORT CASES BY TREATM (A).
MATCH FILES/FILE=*/TABLE=OUTF1/BY TREATM.
SET SEED RANDOM.
COMPUTE RANDOM2 = RV.UNIFORM(0,1).
SORT CASES BY RANDOM2 (A).
COMPUTE ID=$CASENUM.
EXECUTE.
FORMATS ID(F8.0).
LIST ID TREAT.
SORT CASES BY TREAT (A) ID (A).
SPLIT FILE SEPARATE BY TREAT.
LIST ID.