【问题标题】:How to iterate and increase a counter in SPSS?如何在SPSS中迭代和增加一个计数器?
【发布时间】:2019-02-18 13:45:15
【问题描述】:

我想在我的 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 但它不起作用)

最后,我希望像前进这样的变量是 340 和回归是 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 交换,我会得到相同数量的案例。

【问题讨论】:

  • 欢迎来到 SO!我的第一个猜测是您有缺失值 - my_education 中的缺失值或父母双方的教育缺失将导致 achievement 中的缺失值。无论如何,您的第二个策略是正确的 - 在每一行中确定 achievementadvancement 的正确值(可以是 +1、0 -1),然后对所有案例(或按组)求和。 freq 命令在输出中为您提供结果,如果您希望将结果作为数据进行进一步分析,请查找 aggregate 函数。

标签: count statistics spss


【解决方案1】:

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

正如 cmets 中所建议的那样,缺失的结果确实可能是由于缺失数据所致。如果 IF 语句中使用的所有三个变量对于每个案例都是完整的,那么您的 EDIT2 应该为所有案例生成结果。

【讨论】:

    猜你喜欢
    • 2013-01-27
    • 2022-01-22
    • 2015-05-03
    • 1970-01-01
    • 2011-05-06
    • 2010-11-06
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    相关资源
    最近更新 更多