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
(Q) I'm trying to generate orders for blocks of trials comprised of 3 types of
	stimuli (POS, NEG, and NEU), and I need to make sure that there is a
	roughly equal number of all the permutations of pairs of stimuli
	represented in a block of trials, say 2-3 of each pair within a
	block.  There are 9 possible pairs of one valence followed by another-- POS
	followed by NEG, POS followed by NEU, NEG - POS, NEG - NEU, NEU - POS, NEU
	- NEG, POS - POS, NEG - NEG, and finally NEU - NEU.  In a block of 24
	trials, there are 23 total pairs.  I'm generating random orders, and then I
	need a way to count the number of pairs represented in those random
	orders-- anyone know of a way to do this?  I've been tallying them by
	hand-- there must be a better way!

*(A) Posted to SPSSX-L by Raynald Levesque on 2002/03/12.



DATA LIST free
/order (F2) val1 (A3).
BEGIN DATA.
1 POS
2 POS
3 POS
4 NEU
5 NEG
6 NEG
7 NEU
8 NEU
9 NEG
10 NEG
11 NEU
12 POS
13 NEG
14 POS
15 NEG
16 NEU
17 NEG
18 POS
19 NEG
20 POS
21 NEU
22 POS
23 NEU
24 NEU
END DATA.
RECODE val1 (CONVERT) ('POS'=1) ('NEU'=2) ('NEG'=3) INTO v1.
SAVE OUTFILE='c:\\temp\\mydata.sav'.



*////////////////////.
DEFINE !shuffle(fname=!TOKENS(1) /nb=!TOKENS(1))
GET FILE=!fname.
!DO !cnt=1 !TO !nb.
COMPUTE draw=UNIFORM(1).
SORT CASES BY draw.

CREATE v2=LEAD(v1,1).
COMPUTE pair=v1*10+v2.
LIST val1.
FREQ VAR=pair.
!DOEND
!ENDDEFINE.
*////////////////////.

* Use any arbitrary number as the seed.
SET SEED=1987653.

* Do 5 shuffles.
!shuffle fname='c:\\temp\\mydata.sav' nb=5.