select - 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?
解决方案
您需要创建一个包含组均值的新变量(因此每个组中的所有行在此变量中都将具有相同的值 - 组均值)。然后,您可以将每一行与该值进行比较。
首先,我将创建一些示例数据来演示:
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.
.
推荐阅读
- java - 如何通过“类”或“跨类”查找元素?
- ios - 使用子查询进行领域计算和排序
- docker - Docker 会作为高级压缩器提供帮助吗?
- python - 有没有更简单的方法可以使用 pandas read_clipboard 来阅读系列?
- java - 如何处理 DPR 直径以及 DPR 何时发送?发送 DPR 有什么条件吗?
- java - Hibernate:我应该在抽象 dao 中包含 begin transaction 和 commit 吗?
- audio - ffmpeg,如何连接两个流,一个有音频,一个没有音频
- reactjs - 如何在反应中测试url查询字符串
- android - 从一个活动中选择数据并在另一个活动中并排即时更改或在android中的片段
- python-3.x - Python 编译器在打印函数中添加 10^-16 到答案中