Question

I have the following SPSS syntax to count using a conditional

DATASET ACTIVATE Conjunto_de_datos1.
DO IF  (((p7_1 = 1) | (p7_2 = 1)) & (periodo = 2)).
COUNT noque_o_noria=p7_2 p7_1(1).
END IF.
EXECUTE.

the data is the folowing

p7_1    p7_2    periodo
1   1   2
1   0   2
1   1   2
1   1   1
1   1   1
0   1   2

The problem I have is that in the new column each row that meet the rule is given automatically the value 2, and the ones that don't meet the rule are lost values (empty). What should I add to the code above to retrieve me 1 when it meets the rule and 0 when not?

Was it helpful?

Solution 2

There is no point for the COUNT command, so you can use a COMPUTE noque_o_noria = 1 instead and then specify an ELSE condition, e.g.

DO IF  (((p7_1 = 1) | (p7_2 = 1)) & (periodo = 2)).
  COMPUTE noque_o_noria = 1.
ELSE.
  COMPUTE noque_o_noria = 0.
END IF.

OTHER TIPS

You don't need so much syntax to do that. Just

compute noque_o_noria=(p7_2 = 1 or p7_1 = 1) and periodo = 2.

will do.

I suspect that the periodo variable was previously defined, and the DO IF is leaving the old values unchanged.

If the variable is new, then cases bypassed by DO IF will have the sysmis value. For cases that are processed by COUNT, the variable is initialized to zero for each case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top