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
*QUESTION: I would like a macro to show variability given a fixed sample
	size (lets say 100), but changing the number of samples that are taken into
	account. I mean, I would like to show a salary mean calculated as the mean
	of 5 samples, 10 samples, ..., 50 samples (yes, I am trying to show some
	properties of the sampling distribution, central limit theorem, etc. etc.).

* SOLUTION posted to SPSSX-L by Raynald Levesque rlevesque@videotron.ca on 2001/08/09.

SET MPRINT=yes.


* -------------------DEFINE MACRO ---------------------------------------------.
DEFINE !sample(myvar !TOKENS(1) 
		/size !TOKENS(1)
		/nbsampl !CMDEND)
/* myvar = the variable of interest (here we want the mean of salary) */
/* nbsampl = number of samples */
/* size = the size of each samples */.

!LET !first='1'
!DO !ss !IN (!nbsampl)
!DO !count = 1 !TO !size.

GET FILE='c:\\Program Files\\SPSS\\employee data.sav'.

COMPUTE draw=uniform(1).
SORT CASES BY draw.
N OF CASES !ss.

COMPUTE samplenb=!count. 
COMPUTE ss=!ss.

AGGREGATE
  /OUTFILE=*
  /BREAK=samplenb
  /!myvar = MEAN(!myvar) /ss=FIRST(ss).

!IF (!first !NE '1') !THEN
ADD FILES /FILE=*  /FILE='c:\\temp\\sample.sav'.
!IFEND
SAVE OUTFILE='c:\\temp\\sample.sav'.
!LET !first='0'

!DOEND. 
!DOEND. 

VARIABLE LABEL ss !QUOTE(!CONCAT('Number of Samples of size ',!size)).
EXAMINE
  VARIABLES=salary BY ss /PLOT=BOXPLOT/STATISTICS=NONE/NOTOTAL
  /MISSING=REPORT.

!ENDDEFINE.
* ----------------END OF MACRO ----------------------------------------------.


* Call macro (parameters are number of samples (here 5 10 25 35 50) and size of sample (here 10). 
* Thus 5 samples of size 10.
* Thus 10 samples of size 10, etc.
!sample myvar=salary size=10 nbsampl=5 10 25 35 50.