Bookmark and Share

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


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

st: RE: Using wildcards in string variables to drop observations


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Using wildcards in string variables to drop observations
Date   Mon, 30 Sep 2013 14:32:50 +0000

Rainer,

Wildcards in Stata are typically only used in variable names.  The nearest equivalent for what you want to do is regular expressions (functions regexm, regexr, regexs), which I wouldn't recommend for a new user.  Fortunately, there is another alternative:

. drop if strpos(variable,"%")

Regards,
Joe Canner
Johns Hopkins University School of Medicine

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Rainer Maurer
Sent: Monday, September 30, 2013 7:12 AM
To: [email protected]
Subject: st: Using wildcards in string variables to drop observations

Dear Statalisters,
I'm a stata-newy and have the following problem: I want to drop all observations where in a string variable the string "%" appears. I thought the straightforward command would be ' drop if variable = = "*%" '. However, using this command, nothing is eliminated. If I specify the string completly (like ' drop if variable = = "DE12%" '
the observation is eliminated just as I want it. Where is my mistake?
Do wildcards like * not work in these kinds of commands?
Thanks a lot for any piece of help!
Rainer
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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