Dear all,
I have the following code:
I have the variables A1, A2, A3, B, C, & D. I want to create a new variable called dummy that is 1 if any of the variables has values starting with "THIS9".
Now, what I have done above is one way to achieve that, but I appreciate if you could share a better way that checks a varlist at once instead of one at a time.
Thank you in advance.
I have the following code:
Code:
clear set obs 1 g A1="THIS430" g A2="THIS440" g A3="THIS450" g B="THIS99" g C="THIS230" g D="THIS530" gen dummy = strpos(A1, "THIS9") | strpos(A2, "THIS9") | strpos(A3, "THIS9") | strpos(B, "THIS9")
Now, what I have done above is one way to achieve that, but I appreciate if you could share a better way that checks a varlist at once instead of one at a time.
Thank you in advance.
Comment