SPSS语法:将一个分类变量拆分为多个是/否变量

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

SPSS Syntax: spliting one categorical variable into multiple yes/no variables

问题

我有一个分类变量(v0),其中有选项1、2和3。我想将其拆分为3个是或否变量(v1、v2、v3)。

1、2和3不是互斥的,下面是逻辑:

如果1为真,则2和3不为真。
如果2为真,则1为真,但3不为真。
如果3为真,则1到3都为真。

这是我尝试的解决方案:

COMPUTE v1 v2 v3.
FORMATS v1 to v3 (f1).
EXECUTE.

IF (v0 = 1) v1 = 1
    /v2 to v3 = 0.
IF (v0 = 2) v1 to v2  = 1
    /v3 = 0.
IF (v0 = 3) v1 to v3  = 1.
EXECUTE.

VALUE LABELS v1 to v3 0 'No' 1 'Yes' 99 'Missing'.

有更好的方法来做这个吗?或者这是一个可接受的解决方案。

英文:

I have a categorical variable (v0) with options 1, 2 and 3. I want to split this into 3 yes or no variables (v1, v2, v3).

1,2 and 3 are not mutually exclusive, here is the logic:

if 1 is true then 2 & 3 are not.
if 2 is true then 1 & 2 are, but 3 is not.
if 3 is true then 1-3 are true.

This is the solution I've tried:

COMPUTE v1 v2 v3.
FORMATS v1 to v3 (f1).
EXECUTE.

IF (v0 = 1) v1 = 1
    /v2 to v3 = 0.
IF (v0 = 2) v1 to v2  = 1
    /v3 = 0.
IF (v0 = 3) v1 to v3  = 1.
EXECUTE.

VALUE LABELS v1 to v3 0 'No' 1 'Yes' 99 'Missing'.

Is there better way to be doing this? Or is this an acceptable solution.

答案1

得分: 0

这里有多种方法可以做到这一点,以下是其中之一:

计算 V1=any(V0,1,2,3)。
计算 V2=any(V0,2,3)。
计算 V3=(V0=3)。
英文:

There is any number of ways to do this, here's just one of them:

compute V1=any(V0,1,2,3).
compute V2=any(V0,2,3).
compute V3=(V0=3).

huangapple
  • 本文由 发表于 2023年8月10日 23:42:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877329.html
匿名

发表评论

匿名网友

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

确定