Hello,
I have a dataset that contains information on 28 different drugs (variables drug1-drug28) and their positivity levels, but these are string variables currently. see below for an example:
What i want to do is create a separate variable for each drug type that returns a value of 1 if drug1-drug28 contains the following characters "(0)". I've tried, for example,
, but this will return a value of 1 if 0 shows up anywhere. In the example above, in the first observation, "Cocaine (0)" should return a value of 1, but in the last observation, " Benzoylecgonine (Hair) (604)" should NOT return a value of 1.
Thank you for any assistance in syntax you can provide.
I have a dataset that contains information on 28 different drugs (variables drug1-drug28) and their positivity levels, but these are string variables currently. see below for an example:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str33(drug1 drug2 drug3 drug4) str34 drug5 "Tramadol (94.78)" " Benzoylecgonine (125)" " Cocaine (0)" "" "" "Tramadol (95.426)" "" "" "" "" "Tramadol (96.38)" " THC (4.57)" "" "" "" "meta-Hydroxycocaine (Hair) (18.8)" " para-Hydroxycocaine (Hair) (6.4)" " Carboxy-THC (Hair) (2.46)" " Benzoylecgonine (Hair) (218)" " ortho-Hydroxycocaine (Hair) (2.8)" "meta-Hydroxycocaine (Hair) (4.9)" " Norfentanyl (Hair) (24)" " EDDP (Hair) (1421)" " Benzoylecgonine (Hair) (773)" " ortho-Hydroxycocaine (Hair) (4.7)" "para-Hydroxycocaine (Hair) (11)" " Cocaethylene (Hair) (113)" " meta-Hydroxycocaine (Hair) (14)" " Carboxy-THC (Hair) (2.11)" " Benzoylecgonine (Hair) (604)" end
Code:
gen result=regexm(drug1, "(0)")
Thank you for any assistance in syntax you can provide.
Comment