首页 > 解决方案 > Select cases if value is greater than mean of group

问题描述

Is there a way to include means of entire variables in Select Cases If syntax?

I have a dataset with three groups n=20 each (sorting variable grp with values 1, 2, or 3) and results of a pre and post evaluation (variable pre and post). I want to select for every group only the 10 cases where the pre value is higher than the mean of that value in the group.

In pseudocode:

select if pre-value > mean(grp)

So if the mean in group 1 is 15, that's what all values from group one cases should be compared to. But at the same time if group 2's mean is 20, that is what values from cases in group 2 should be compared to.

Right now I only see the MEAN(arg1,arg2,...) function in the Select Cases If window, but no possibility to get the mean of an entire variable, much less with an additional condition (like group).

Is there a way to do this with Select Cases If syntax, or otherwise?

标签: selectstatisticsspss

解决方案


您需要创建一个包含组均值的新变量(因此每个组中的所有行在此变量中都将具有相同的值 - 组均值)。然后,您可以将每一行与该值进行比较。

首先,我将创建一些示例数据来演示:

data list list/grp pre_value .
begin data
1 3
1 6
1 8
2 1
2 4
2 9
3 55
3 43 
3 76
end data.

现在您可以计算组均值并选择:

AGGREGATE  /OUTFILE=* MODE=ADDVARIABLES  /BREAK=grp  /GrpMean=MEAN(pre_value).
select if pre_value > GrpMean.

.


推荐阅读