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
Graph Scale and Text when using Graph Combine CommandI want to combine graphs, but when I do, the formatting is almost always problematic. If I have thr…
How can I select a study population matching a published prospective trial?Dear Experts, I have a very large population database of patients who have been treated for localiz…
weighted random effects model with clustered SEHello: I want to estimated a weighted RE model with clustered standard errors. The xtreg does not a…
Estimate store using lincomHi everyone, I hope you are doing great. I am trying to store the results of a lincom to later use …
Asking for the explanation of the result of DDD ?I am following Stata package to run the did_imputation of Borusyak,2021 in using the DiD imputation …
Subscribe to:
Post Comments (Atom)
0 Response to Conditioning on a string variable
Post a Comment