Get random sample of various size then calculate statistics
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 | SET MPRINT=yes. * code: Raynald Levesque rlevesque@videotron.ca. * -------------------DEFINE MACRO ---------------------------------------------. DEFINE !sample(myvar !TOKENS(1) /nbsampl !TOKENS(1) /size !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 (!size) !DO !count = 1 !TO !nbsampl. 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 'Sample 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 20) and sizes of sample (here 5, 10,15,30,50). * Thus 20 samples of size 5. * Thus 20 samples of size 10, etc. !sample myvar=salary nbsampl=20 size= 5 10 15 30 50. |