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]

Re: st: Remove the middle part of a string variable


From   Phil Schumm <[email protected]>
To   Statalist Statalist <[email protected]>
Subject   Re: st: Remove the middle part of a string variable
Date   Sun, 5 Jan 2014 18:50:36 -0600

On Jan 5, 2014, at 6:30 PM, Nick Cox <[email protected]> wrote:
> On Jan 5, 2014, at 6:27 PM, Phil Clayton <[email protected]> wrote:
>> replace myvar=regexs(1) + regexs(2) if regexm(myvar, "(.*)\..*([A-Z])")
> 
> Good, but don't -replace- in this situation.


Also, based on the problem description, you may not want the greedy .* in the middle.  For example, the following would handle multiple letters at the end:

   gen newvar = regexs(1)+regexs(2) if regexm(myvar,"([0-9]+)\.[0-9]+([A-Z]+)")
   replace newvar = myvar if mi(newvar)


-- Phil


*
*   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