Creating a New Variable to act as a Variable Flag
If an SPSS data frame contained six variables, and from such, you wished to create an additional variable to act as a flag to identify the instances in which one of the six variables was equal to the number: “1”, the line of code to establish this task would resemble the following:
if(Var1 = 1 OR Var2 = 1 OR Var3 = 1 OR Var4 = 1 OR Var5 = 1 OR Var6 = 1) VarFlag = 1.
exe.
In the case of our example above, a new variable, “VarFlag”, would be created and populated with the value of “1” whenever any of the aforementioned values equaled “1”.
If instead, you wished to only identify instances in which “Var1” and “Var2” are equal to “1”, the code below could be utilized:
if (
Var1 = 1 AND Var2 = 1
) VarFlag = 1.
EXECUTE.
If you wished to flag for instances in which “Var1” contained a missing value, the following code be utilized to achieve such:
if ( MISSING(Var1) ) VarFlag = 1.
exe.
Finally, if you desired to only identify instances in which a text field contains a value, the following code could be utilized:
if (Var1 NE "") VarFlag = 1.
exe.
That’s all for now, Data Heads. I heavily encourage you to research this topic to better build your arsenal of analytic tools.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.