如何在SPSS中迭代并增加计数器?

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

我想在我的SPSS数据集中计算教育程度。我有一些编程经验,但是我对语法仍然有兴趣。

我有一个变量my_education。我想将my_educationeducation_fathereducation_mother进行迭代比较。如果my_education比我父母的大,我有进步,如果没有,我也没有进步。所有变量均采用数字编码。

advancement = 0
regress = 0

if my_education > max(education_father, education_mother) advancement ++1

((我试过++ 1或+1,但不起作用)

最后,我希望像progression这样的变量为340,而regress为190。

我猜主要问题是如何使用代码遍历整个数据集并在末尾增加计数器。有人可以帮我吗?

编辑:

我也尝试过这个:

do if (my_education > max(education_mother &education_father)).
Compute advancement =1. -> i want this variable to increase though
Else if (my_education < max(education_mother &education_father)).
Compute regress =1. -> same here, to give the exact number of increases or regresses

EDIT2:和这个:

if (my_education > max(education_mother,education_father)) achievement=1.
if (my_education < max(education_mother,education_father)) achievement=2.
if (my_education = max(education_mother,education_father)) achievement=3.
freq achievement.

但是仍然有很多案件没有计算在内,大约占所有案件的70%。另外,如果将MAX与MIN交换,则得到的案件数也相同。

count statistics spss
1个回答
0
投票

SPSS中的IF和COMPUTE分别对数据中的行或个案进行操作。为了汇总各个案例的信息,您必须按照注释中的建议通过诸如FREQUENCIES或AGGREGATE之类的过程将这些单个案例计算的结果制成表格,或者添加计数器变量并使用LAG函数从前面的内容中添加内容情况。

确实,如评论中所建议的,缺少结果可能是由于缺少数据。如果在每种情况下IF语句中使用的所有三个变量都完整,那么您的EDIT2应该会在所有情况下产生结果。

© www.soinside.com 2019 - 2024. All rights reserved.