在SPSS中循环,反复抽取样本,从每个样本中得到描述性统计数据



我想从数据集中绘制大小为50的样本100次,并从输出窗口中的每个样本中获得描述性统计信息。我已经使用了以下代码,但得到警告!!

loop # = 1 to 100.
USE ALL. 
do if $casenum=1. 
compute #s_$_1=50. 
compute #s_$_2=10251. 
end if. 
do if  #s_$_2 > 0. 
compute filter_$=uniform(1)* #s_$_2 < #s_$_1. 
compute #s_$_1=#s_$_1 - filter_$. 
compute #s_$_2=#s_$_2 - 1. 
else. 
compute filter_$=0. 
end if. 
VARIABLE LABELS filter_$ '50 from the first 10251 cases (SAMPLE)'. 
FORMATS filter_$ (f1.0). 
FILTER  BY filter_$. 
EXECUTE. 
DESCRIPTIVES VARIABLES=myvar1 
/STATISTICS=MEAN STDDEV VARIANCE SEMEAN.
end loop.
exe.    

我得到的第一个警告为:

>Warning # 142.  Command name: USE 
>LOOP has no effect on this command.   

我是SPSS新手,从来没有做过loop
我正在使用SPSS版本22。
任何帮助都将不胜感激。如果是重复问题,请道歉。

一种方法是将您试图在宏中使用的示例命令和描述性命令包装起来:

DEFINE !repsample(times=!TOKENS(1) / size=!TOKENS(1) / maxn = !TOKENS(1) / vars=!CMDEND)
!DO !cnt=1 !TO !times.
do if $casenum=1.
compute #s_$_1=!size.
compute #s_$_2=!maxn.
end if.
do if  #s_$_2 > 0.
compute filter_$=uniform(1)* #s_$_2 < #s_$_1.
compute #s_$_1=#s_$_1 - filter_$.
compute #s_$_2=#s_$_2 - 1.
else.
compute filter_$=0.
end if.
FORMATS filter_$ (f1.0).
FILTER  BY filter_$.
DESCRIPTIVES VARIABLES= !vars
/STATISTICS=MEAN STDDEV VARIANCE SEMEAN.
!DOEND
!ENDDEFINE.

上面的宏有四个参数- times为样本,size为样本,maxn为案例,vars为使用(接受由空格分隔的变量列表)。我们可以这样命名它:

!repsample times = 100 size = 50 maxn = 10251 vars = myvar1.

最新更新