Hi,
I'd like to identify observations when a string variable contains multiple substrings.
In my dataset, I have a string variable containing crime descriptions. For that string variable, I want to identify when "REG" and "GUN" appear together in the same cell.
The data is messy and not standardized. Here is an example of how some of the strings look:
crime
GUN OFFENDER REGISTRATION
GUN OFFENDER-FAIL TO REGISTER
GUN OFFENDER/FAIL REG OFFENDER
GAS/AIR/PAINTBALL GUN: POSSESS
FIRING HANDGUN IN CITY LIMITS
FRAUDULENT POSSESSION OF VEH OWNERSHIP REG. PLATE
KNOWINGLY HOLDING FALSIFIED VEH. REG. PLATE
I've successfully used the strpos command to isolate observations containing a single substring, i.e. :
l if strpos(crime, "REG")
l if strpos(crime, "GUN")
And I've been able to identify observations that contain either one substring or another, i.e. :
l if strpos(crime, "REG" "GUN")
But I haven't been able to figure out how to identify if a single cell contains both "REG" and "GUN".
Any advice is appreciated.
Related Posts with Identify if single cell contains multiple substrings
Normalize variable as an expanding windowHi, I would like to normalize the price of the following as an expanding window taking into account…
Reminder: UK Stata Conference submission deadline 26 MayUK Stata Conference, 7-8 September 2023: reminder I'm bumping the thread at https://www.statalist.o…
How do I find out which excel file was imported into STATA (origin of data?)Hey all, Months ago, I imported an excel file into stata for analysis. However, I would like to do…
Query on ordering coefficients from multiple models when using coefplotHi All We need help with using the coefplot command. Briefly, we have run a series logistic regress…
generating many dummy variables with the var name and label nameHi all, Although I was going through some of the website links, I could not solve my issue. So, I am…
Subscribe to:
Post Comments (Atom)
0 Response to Identify if single cell contains multiple substrings
Post a Comment