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:how to delete anything in the bracket for a string variable


From   Tirthankar Chakravarty <[email protected]>
To   [email protected]
Subject   Re: st:how to delete anything in the bracket for a string variable
Date   Sat, 8 Oct 2011 22:05:19 -0700

This should work:

***********************************************
clear*
input id   str50     name
1         "John (joined before 2005)"
2         "Jenny"
3         "Kai (joined in 2006; left in 2008)"
4         "Tom (inconsistent dates)"
end
replace name = regexr(name, "\((.)+\)", "")
li
***********************************************

T

On Sat, Oct 8, 2011 at 9:17 PM, Amanda Fu <[email protected]> wrote:
> Hi All,
>
> I wonder if someone can give me some suggestion on delete anything in
> the bracket for a string variable. A string variable in my data set
> has some notes in bracket for part of the observations. I want to
> remove the brackets and anything in them
>
> An example is like:
> -------------------------
> id        name
> 1         John (joined before 2005)
> 2         Jenny
> 3         Kai (joined in 2006; left in 2008)
> 4         Tom (inconsistent dates)
> -------------------------.......
> I would like to delete anything in the () for the variable "name" so
> that only names are kept. But the content in the brackets are not the
> same. I think that causes the -substr- does not work for this purpose.
>
> Thank you !
>
> Best wishes,
> Amanda Fu
> *
> *   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/
>



-- 
Tirthankar Chakravarty
[email protected]
[email protected]

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


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