0

我汇总了以下宏以获取各种大小的随机样本,然后计算 MEAN 给定次数。我还想在 MEAN 旁边计算 STDEV。我尝试了对脚本的各种修改,但我很难应用我认为的正确语法。谢谢你的帮助。

问候

安迪

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='E:\Monte carlo testing\s1.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='E:Monte carlo testing\sample.sav'.
!IFEND
SAVE OUTFILE='E:\Monte carlo testing\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.


!sample myvar=VAR00001 nbsampl=200 size= 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100
4

1 回答 1

0

这有帮助吗?

AGGREGATE
 /OUTFILE=*
 /BREAK=samplenb
 /!myvar = MEAN(!myvar)
 /sd = STDEV(!myvar)
 /ss=FIRST(ss).
于 2013-03-06T11:15:21.963 回答