Hi, I'm new to Stata and would like to know how to condition on a string variable. I have a variable 'drugs' with names of different drugs e.g., paracetamol, penicillin etc. I want to create new variables as 'Paracetamol' or 'Antibiotics' where I want to flag as '1' the respective drug e.g.
gen paracetamol = 1 if drugs=="paracetamol" | "paracet" | "panadol" | "padol"
gen antibiotics = 1 if drugs=="penicillin" | "amoxicillin" | "antibio"
While I'm trying to do it, I get the error 109 (type mismatch). I get the same error even after encoding the 'drugs' variable as a new variable "drugs_new".
Kindly help!
Related Posts with Conditioning on a string variable
How to simplify conditional statementsDear all, Code: * Example generated by -dataex-. To install: ssc install dataex clear input float(…
optimize issue with evaluator in a class Hi, I have the following two functions defined as public in the class nelogit_fp. Code: // ML d2…
How to choose between Pooled OLS/Random Effects?Hello, I am currently working on my undergrad thesis with the topic factor determinants for imports…
Help with foreach of string variablesHi STATA experts, I am using foreach to run a loop for a list of string variables. The command runs…
How to export file after regression?Hi everyone, I started learning STATA recently after learning some object-oriented programming lang…
Subscribe to:
Post Comments (Atom)
0 Response to Conditioning on a string variable
Post a Comment