Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement SPSS使用if语句在同一字段中使用多个ID计算新变量_If Statement_Spss - Fatal编程技术网

If statement SPSS使用if语句在同一字段中使用多个ID计算新变量

If statement SPSS使用if语句在同一字段中使用多个ID计算新变量,if-statement,spss,If Statement,Spss,我需要在SPSS中计算一个新变量,如果ID在“秋季”和“春季”中都有分数,则该变量的读数为“1”。下面是数据示例。我想要ID#14576=0的输出,因为它只有春季的评级,但是ID#10869=1,因为它在春季和秋季都有评级。timePeriod变量是“string”格式的,所以我尝试了下面的公式,但它只是在所有ID旁边提供了“0”。你知道我该怎么做吗 compute bothtimeperiods=0. if (timeperiod="Fall" and timeperiod="Spring")

我需要在SPSS中计算一个新变量,如果ID在“秋季”和“春季”中都有分数,则该变量的读数为“1”。下面是数据示例。我想要ID#14576=0的输出,因为它只有春季的评级,但是ID#10869=1,因为它在春季和秋季都有评级。timePeriod变量是“string”格式的,所以我尝试了下面的公式,但它只是在所有ID旁边提供了“0”。你知道我该怎么做吗

compute bothtimeperiods=0.
if (timeperiod="Fall" and timeperiod="Spring") bothtimeperiods=1.
数据如下:

ID      rating  timePeriod
14576   3.0     Spring
14576   2.0     Spring
14576   5.0     Spring
14576   4.0     Spring
10869   1.0     Spring
10869   2.0     Spring
10869   4.0     Spring
10869   4.0     Spring
10869   1.0     Fall
10869   5.0     Fall
10869   5.0     Fall
10869   2.0     Fall

一种方法是计算表示春天或秋天的两个虚拟变量,然后使用
AGGREGATE
来说明人员Id中是否出现任何虚拟变量。这将为您提供信息。然后你需要检查一下。下面的例子

DATA LIST FREE / ID  (F5.0) rating  (F3.1) timePeriod (A6).
BEGIN DATA
14576   3.0     Spring
14576   2.0     Spring
14576   5.0     Spring
14576   4.0     Spring
10869   1.0     Spring
10869   2.0     Spring
10869   4.0     Spring
10869   4.0     Spring
10869   1.0     Fall
10869   5.0     Fall
10869   5.0     Fall
10869   2.0     Fall
11111   3.0     Spring
22222   4.0     Fall
END DATA.

COMPUTE AnySpring = (timePeriod = "Spring").
COMPUTE AnyFall = (timePeriod = "Fall").
AGGREGATE OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES
  /BREAK ID
  /AnySpring AnyFall = MAX(AnySpring AnyFall).

COMPUTE bothTimeperiods = (AnySpring = 1) AND (AnyFall = 1).
EXE.

数据表翻译得很奇怪。数据在第一列中有重复ID,第二列包含评级,第三列标识变量是记录在每种情况的春季还是秋季。请注意,IF谓词中的条件永远不可能为true。Timeperiod不能同时具有两个值