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
Bootstrapping with aregDear All, I am having difficulty bootstrapping with areg. I have a low number of clusters and have …
Month-wise regressions using daily dataDear Stata comunity, I need to run month-wise fama and french three factor model regressions using …
Lasso: Fitting mixed-effects logit modelsHi, I haven't been able to find a reference for doing this in Stata, but was wondering if anyone ha…
Standardized Beta CoefficientHaving run my linear regression analysis that contains two independent variables and one dependent v…
How do you generate a categorical variable which takes on values 0 and 1 in 60% and 40% observations respectively?The problem is that the output always shows a little or above it. For example, there are 10000 obser…
Subscribe to:
Post Comments (Atom)
0 Response to finding keywords in string variables
Post a Comment