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
T-test of difference between two regression coefficients within same modelHello, I have one single regression model estimating the coefficients (b) of two independent variab…
Same model, different dependent variables: Single Y label in the combined graphDear Statalisters, I have troubles using graph combine, I don’t know how to get a single y label fo…
Saving tabstat results in new variablesHello, I'm using tabstat to generate weighted standard deviations, by year, for two variables in a …
line graph at country and year level for several variables using levelsofHello all, I have a panel long format dataset that can be found attached containing year and countr…
conditions by groupHi there, I have the following data and I want a variable that is 1 if, by firmid, there is at least…
Subscribe to:
Post Comments (Atom)
0 Response to Conditioning on a string variable
Post a Comment