Dear Statalister
I'm working on a dataset and I need to create a dummy variable equals 1 if the string variable contain words or phrases from a list of keywords. I'm using the following code:
global keyword "AA BB CC"
foreach i of global keyword3{
gen Dummy_`i'= strpos(string, "`i'") > 0
}
This code works find if the keyword is a single word. However if it is a phrase, such as "low AA" or "middle AA" then the code will create different variables for each word in the phrase.
The list of keywords are very long so I would prefer to use loop function for it.
I would highly appreciate if you can please help me to come up with a way to deal with this issue.
Thank you very much in advanced
Related Posts with finding keywords in string variables
Convert string to time including millisecondsI have a variable containing strings in the following format StringVar "2018-12-27 14:28:41.4861930…
Joinby two variablesDear statalisters, I am trying to merge two datasets and I have some problems. I started yesterday …
Concatenate of a string and a numberDear statalister, I am trying to merge to database, I would like to try using a concatenate of coun…
1-to-(n) Propensity score matching without replacementHi, I was hoping if someone can help me with this. I have a data set with about 100 cases and 6000 …
getting estimates when using bayes prefix for melogitHi Stata forum members, I need some advice on how to get estimates after fitting melogit using baye…
Subscribe to:
Post Comments (Atom)
0 Response to finding keywords in string variables
Post a Comment