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
Creating local (or global) macro of past date (or range), in DDNNCCYY formatHi, I am trying to save a date range as a macro. I have it working to a degree with: Code: su dat…
Combining/Merging Duplicate ObservationsHi all, I have a dataset containing over 300'000 observations and have identified a few (1'725) dupl…
Theoretical question about the importance of stationarity in panel data for OLS estimatorDear all, I have been doing some reading on the importance of the stationarity property for the dep…
marginsplot after running a multinomial logit: how to plot the cumulative probabilities as an area graph Hello, I have been using the marginsplot function plot predicted probabilities after mlogit estimat…
reghdfe, clustering and crit. values -> adjusted?Dear all, I am using reghdfe and have few clusters. Throughout, I Wild-Cluster bottstrap my p-value…
Subscribe to:
Post Comments (Atom)
0 Response to finding keywords in string variables
Post a Comment