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
Does this situation require a reshape long, or something different?Dear Statalisters, I would like to efficiently convert the following data: Code: * Example genera…
Extracting numbers from a string variable to put into a new variableHello, A few of my colleagues reviewed police investigative case files and measured the victims' de…
Stability test- how to interpret the results?Hi everyone, I am currently doing a time-series analysis using the VECM. I have one cointegrating …
Importing Excel variables into Stata with shortened namesDear all, I am working with a dataset that contains information about individuals and their relatio…
Problems with table command in Stata17I have some problems using table command in Stata 17 Code: webuse nhanes2l table (sex race) () () …
Subscribe to:
Post Comments (Atom)
0 Response to finding keywords in string variables
Post a Comment