Hi Sharad,
I first converted "alcohol" from a string variable to a new ordered categorical variable (i.e. alcohol_num) using the "encode" function. I then used the "recode" function on the new categorical variable to assign the appropriate numbers to 1, 0, and missing. You can use the "codebook" function to see what numbers you need to assign to 1, 0 and missing and plug them into the range indications (i.e. the "min/2" below would assign the "1" to any value of 2 or less, AKA in the range of minimum to 2).
recode original variable (min/2 = 1 "True") (3/3 = 0 "False")(4/max = .), gen(new variable name)
That seemed to work for me. I think Michael's way would work as well and probably better if the numbers of the original variable weren't ordered in a way that you could use the ranges. Hope this is helpful.
I first converted "alcohol" from a string variable to a new ordered categorical variable (i.e. alcohol_num) using the "encode" function. I then used the "recode" function on the new categorical variable to assign the appropriate numbers to 1, 0, and missing. You can use the "codebook" function to see what numbers you need to assign to 1, 0 and missing and plug them into the range indications (i.e. the "min/2" below would assign the "1" to any value of 2 or less, AKA in the range of minimum to 2).
recode original variable (min/2 = 1 "True") (3/3 = 0 "False")(4/max = .), gen(new variable name)
That seemed to work for me. I think Michael's way would work as well and probably better if the numbers of the original variable weren't ordered in a way that you could use the ranges. Hope this is helpful.