Creating one variable from three, SPSS 将三个变量合并为一个,SPSS

huangapple go评论51阅读模式
英文:

Creating one variable from three, SPSS

问题

能否有人善意地帮助解决SPSS语法的问题。我遇到了错误,但不明白为什么。
我有3个变量:
Var1(取值为1和2)
Var2(取值为1和2)
Var3(取值为1、2和3)

我想基于这三个变量创建一个新变量,其中每个变量上的值为1(var1=1 AND VAR2 = 1 AND Var3 = 1)编码为1,所有其他组合编码为2。

我已经编写了以下代码,但遇到错误,无法理解原因。

DO IF (Var1 = 1 AND Var2 = 1 AND Var3 = 1) COMPUTE ADL_independence_before_stroke = 1.
IF ELSE COMPUTE ADL_independence_before_stroke = 2.
END IF.
EXECUTE.

谢谢。

英文:

Cam someone be kind and help with SPSS syntax. I get error and do not understand why.
I have 3 variables:
Var1 (values 1 and 2)
Var2 (values 1 and 2)
Var3 (values 1, 2, and 3)

I want to create one variable based on these three, where values 1 on each variable ((var1=1 AND VAR2 = 1 AND Var3 = 1) is coded as 1, and all other combinations are coded as 2.

I have written this code but get error, can not understand why.

DO IF (Var1 = 1 AND Var2 = 1 AND Var3 = 1) COMPUTE ADL_independence_before_stroke = 1.
    IF ELSE COMPUTE ADL_independence_before_stroke = 2.
    END IF.
EXECUTE.

Thanks.

答案1

得分: 1

你已经接近成功,但需要更正你的语法:

如果 (Var1 = 1 且 Var2 = 1 且 Var3 = 1) 则
    计算 ADL_independence_before_stroke = 1
否则
    计算 ADL_independence_before_stroke = 2
结束如果
执行

以下是缩写版本:

计算 ADL_independence_before_stroke = 2 - (Var1 = 1 且 Var2 = 1 且 Var3 = 1)
英文:

You're nearly there but need to correct your syntax:

DO IF (Var1 = 1 AND Var2 = 1 AND Var3 = 1).
    COMPUTE ADL_independence_before_stroke = 1.
ELSE.
    COMPUTE ADL_independence_before_stroke = 2.
END IF.
EXECUTE.

And here's a shortened version:

compute ADL_independence_before_stroke = 2- (Var1 = 1 AND Var2 = 1 AND Var3 = 1).

huangapple
  • 本文由 发表于 2023年6月8日 22:50:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定