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
Only Keeping Children if Their Parents are in the SurveyHi All, I am trying to make a child file where I only keep observations of those children who have …
Reshape long to wideHello, Here is the data that I want to reshape to wide format, my sample is around 7.5 million obse…
Trend analysisIf we have following data, which includes rates in each age group with corresponding 95%CI and stand…
Desingplot without showing the missing valuesSuppose i have the following data in which the variables have some missing values. I want to show th…
Plotting moderating effects: 1. Margin plots empty output issue; 2. Solutions for 3-way margin plots with c. and i.Dear Stata experts, please help me to find a mistake in my code. It worked fine just 3 days ago but…
Subscribe to:
Post Comments (Atom)
0 Response to finding keywords in string variables
Post a Comment