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
Change in probablity of being downgraded as the explanatory variable change from the bottom (30%) to the top (30%) of the sampleDear all, I am sorry to bother you. I was wondering how one could calculate the change in probablit…
Spatial Panel Data - matsize Hello everyone. hope you are fine and safe. I have Data for 134 countries from 2004 to 2018. When I…
Training sample for lasso and them making out of sample predictionsDear All I have created a loop to generate forecasts using a lasso regressions that (I hope) are co…
Interpretation of clogithet regression (discrete choice experiment)Hi all, For my masterhtesis I've performed a discrete choice experiment. Currently I'm running diff…
Estimating the Effect of a given variable on mortality ratesHi everyone, Below is an example from my dataset. datediag dead dateexit id perdiag agegrp 4429 1 …
Subscribe to:
Post Comments (Atom)
0 Response to Conditioning on a string variable
Post a Comment