Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Eric Booth <ebooth@ppri.tamu.edu> |
To | "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: replacing asterisks in a string |
Date | Mon, 18 Oct 2010 18:43:53 +0000 |
<> ***********! clear inp str10(v1) "*" "(" ")" "test(*)" "tes*t2(*)*" end g v2 = strpos(v1, `"("') g v3 = strpos(v1, `"*"') g v2a = subinstr(v1, `"("', "", .) g v3a = subinstr(v1, `"*"', "", .) //all together// foreach s in * ( ) { replace v1 = subinstr(v1, `"`s'"', "", .) } ***********! - Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 On Oct 18, 2010, at 1:30 PM, Lim, Raymond wrote: > Hello Statalisters, > How does one flag a string containing an asterisk, which in Stata is a wildcard? I want to flag the observations with an asterisk and then delete the asterisk. This is what I would do to flag/delete a parenthesis. > > replace flag_parenthesis=1 if strmatch(varname, "*)") > replace varname=subinstr(varname,")","",.) > > Thanks! > -Raymond > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/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/statalist/faq * http://www.ats.ucla.edu/stat/stata/