Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to identify multiple substrings within a string

From   Nick Cox <>
Subject   Re: st: How to identify multiple substrings within a string
Date   Wed, 16 Jan 2013 23:31:40 +0000

Note that as in elementary algebra a check lies in your own hands: you
can check that each ( is matched by a ) and each [ by a ].

Also the last commands start

gen ...

tab ...

On Wed, Jan 16, 2013 at 10:34 PM, ToveLysa Fitzgerald
<> wrote:
> I seem to be having difficulty with the code below.
> When I run the code I am getting the error message "too many ')' or ']'"
> When I try to alter the brackets I get the error message "type mismatch"
> Does anyone have any suggestions?

Ryan Kessler

> input str50 string
> "diarrhoea"
> "nil diarrhoea"
> "no vomiting/diarrhoea"
> "no text text text text vomiting/diarrhoea"
> "denies diarrhoea/vomiting"
> end
> gen nodi = (regexm(lower(string), "(nil |no |denies )(.*)(diarrhoea)") & length(regexs(2)) <= 10) tab nodi
> Change the 10 as you see fit.

On Tue, Jan 15, 2013 at 4:36 PM, ToveLysa Fitzgerald
<> wrote:

>> Thank you, that piece of code picked up nil/no/denies cases but it also picked up some cases where nil/no/denies was completely irrelevant to the term diarrhoea as these terms preceeded a large amount of text prior to the occurrence of diarrhoea. Is there any way you can refine the code to limit the number of characters/spaces that occur between the terms nil/no/denies and diarrhoea?

Ryan Kessler

>> input str30 string
>> "diarrhoea"
>> "nil diarrhoea"
>> "no vomiting/diarrhoea"
>> "denies diarrhoea/vomiting"
>> end
>> gen nodi = regexm(lower(string), "(nil |no |denies )(.*)(diarrhoea)")
>> tab nodi

Michelle T. Butler <> wrote:

>>> I am searching a string variable for cases who don't have diarrhoea.I need to identify records where the terms nil, no or denies preceeds the term diarrhoea in the same sentence.I have already identified that these terms do not always immediately preceed diarrhoea eg. No vomiting/diarrhoea, so I am looking for a way to extract all observations where nil, no, denies occurs in close proximity to diarrhoea, ignoring spelling errors/upper/lower case variations etc.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index