用条件计算出现次数

问题描述 投票:1回答:1

我正在尝试计算电子邮件在我的数据中显示的次数。我目前正在使用此代码:

AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=Email 
/Number=N.

这工作正常,但缺少一个我需要的条件。

我有另一个变量:周(数字),选项1,2,3,4,5或6。

我只希望SPSS计算电子邮件,如果它们在第6周出现在某个时刻。

例如:

  Email            Week         N
[email protected]         6          2
[email protected]       3          
[email protected]       4         
[email protected]    6          1
[email protected]         4          2

所以你可以看到,因为[email protected]至少出现在第6周,所以我希望它能够计算出她在电子邮件中出现的其余部分(包括那些不在第6周的那些)。但比尔,他两次出现在档案中,但我从不想算他,因为在第6周都没有实例。

如何编辑我的语法来完成此任务?谢谢!

spss
1个回答
0
投票

首先,重新创建示例数据:

data list list/email(a50) week(f1).
begin data
"[email protected]" 6
"[email protected]" 3
"[email protected]" 4
"[email protected]" 6
"[email protected]" 4
end data.

现在运行:

* Identifying emails that had week 6 at least once:  .
if week=6 has6=1.
aggregate out=* mode=addvariables overwrite=yes/break=email /has6=max(has6).
* now to count occurences.
aggregate out=* mode=addvariables /break=email /n=sum(has6).
© www.soinside.com 2019 - 2024. All rights reserved.