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
Export variance covariance matrix to csv fileFor example, sysuse auto, clear I want to export the variance - covariance of variable price mpg h…
reg2hdfespatialDear all, I want to use this link to install the user-written command -reg2hdfespatial-in Stata. ht…
Generating Quarters from date variableHi All, I want to generate quarters in my data set. I have my date variable in the D-M-Y format. I …
Oaxaca with instrumental variableDear all, I am trying to use an Oaxaca- Blinder decomposition to see if a variable of interest cont…
calculate score in StataHello, I gave variables like this: Array Which means: 0. Not using 1. Pill 2. IUD 3. Inje…
Subscribe to:
Post Comments (Atom)
0 Response to finding keywords in string variables
Post a Comment