缺失值的逻辑条件
Logical conditions with missing values
我正在使用 Transform > Compute Variable 对两个变量 (B,C) 进行或运算。我的两个变量可以有值 1、2 或 3。我想计算第三个变量,如果 B 或 C 为 1,则为 1,否则为零。这行得通
A = (B=1) | (C=1)
但如果缺少 B 或 C,我 运行 就会遇到麻烦。我想要的是
if B and C exist and B or C equals 1, A = 1
if B and C exist and neither equals 1, A = 0
if B is missing and C is missing, A = missing
if B or C is 1 and the other value is missing, A = 1
if B or C is not 1 and the other value is missing, A = 0
我可以使用 Transform > Compute Variable 来完成这个还是我需要其他方法?
你可以用语法 window 来写这个。 If variable exists
翻译为 if ~miss(variable)
if ~miss(B) and ~miss(C) and any(1,B,C) A=1.
if ~miss(B) and ~miss(C) and ~any(1,B,C) A=0.
if miss(B) and miss(C) A=$sysmis.
if miss(B) or miss(C) and any(1,B,C) A=1.
if miss(B) or miss(C) and ~any(1,B,C) A=0.
EXECUTE.
或者,如果我理解正确的话:
Compute A=0.
if any(1,B,C) A=1.
if miss(A) and miss(B) A=$sysmis.
EXECUTE.
这是一个衬垫:
compute A=max((B=1), (C=1)).
exe.
您可以通过转换菜单执行此操作,但我建议您习惯使用语法(的强大功能)。
我正在使用 Transform > Compute Variable 对两个变量 (B,C) 进行或运算。我的两个变量可以有值 1、2 或 3。我想计算第三个变量,如果 B 或 C 为 1,则为 1,否则为零。这行得通
A = (B=1) | (C=1)
但如果缺少 B 或 C,我 运行 就会遇到麻烦。我想要的是
if B and C exist and B or C equals 1, A = 1
if B and C exist and neither equals 1, A = 0
if B is missing and C is missing, A = missing
if B or C is 1 and the other value is missing, A = 1
if B or C is not 1 and the other value is missing, A = 0
我可以使用 Transform > Compute Variable 来完成这个还是我需要其他方法?
你可以用语法 window 来写这个。 If variable exists
翻译为 if ~miss(variable)
if ~miss(B) and ~miss(C) and any(1,B,C) A=1.
if ~miss(B) and ~miss(C) and ~any(1,B,C) A=0.
if miss(B) and miss(C) A=$sysmis.
if miss(B) or miss(C) and any(1,B,C) A=1.
if miss(B) or miss(C) and ~any(1,B,C) A=0.
EXECUTE.
或者,如果我理解正确的话:
Compute A=0.
if any(1,B,C) A=1.
if miss(A) and miss(B) A=$sysmis.
EXECUTE.
这是一个衬垫:
compute A=max((B=1), (C=1)).
exe.
您可以通过转换菜单执行此操作,但我建议您习惯使用语法(的强大功能)。