Creating a dummy variable from a string variable

I would like to create a dummy variable from a string variable (Q1) with different comments in it with syntax. If Q1 is empty, insert zero in Q1_d, and if Q1 contains text inside, insert it in Q1_d.

+3


source to share


1 answer


COMPUTE Q1_d=LENGTH(Q1)>0. 

      



Which will create a 0/1 dichotomous variable Q1_d. If there are data / characters in the string data of the string in Q1, then 1 (one) will be assigned in Q1_d else, if Q1 is an empty string, then 0 (zero) will be assigned.

+2


source







All Articles