Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: RE: AW: Dropping string observations that have a sequence of characters

From   "Nick Cox" <>
To   <>
Subject   st: RE: AW: Dropping string observations that have a sequence of characters
Date   Wed, 28 Apr 2010 11:04:33 +0100

I'd agree with Martin that -strpos()- offers the simplest solution here.
There is no need for, although no harm in, regexp solutions. 

But George's example, although presumably concocted rather than
indicative of an astronomical or astrological problem, raises a detail
that could be important for his real problem. Suppose you capitalised
the planet names consistently. Then 

if strpos(myvar, "ur") > 0 

would not catch "Uranus". If you wanted that to happen, there are
various solutions including 

if strpos(lower(myvar), "ur") > 0

The abbreviation 

if strpos(lower(myvar), "ur") 

is also possible here, as in this kind of problem the result of
-strpos()- is non-zero (regarded as logically true) precisely when it is
positive. That is -strpos()- cannot return a negative value. 


Martin Weiss


input str7 myvar

list, noo

drop if strpos(myvar , "ur")!=0

list, noo
George Chioran

How can you delete observations from a variable that contains strings
that have
the letters "ur" for instance.

For example if the variable has the observations: "venus" "mercury"
"Jupiter" "saturn" "uranus" "Neptune". The how could I delete the
observations that contain the letters "ur", in this case "saturn" and
"uranus" ?

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index