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: getting part of strings


From   Rebecca Pope <rebecca.a.pope@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: getting part of strings
Date   Sat, 26 Mar 2011 14:28:07 -0500

Daniel,
What is the end result you are trying to achieve? My guess is that you
want to isolate the name, but I want to verify that. Could you post an
example of what you'd like the final data to look like? A little more
information about your string variable would also be helpful (e.g. Is
there only a fixed set of non-name values that are included? What are
these values or too many to list?)

Thanks,
Rebecca



On Sat, Mar 26, 2011 at 12:05 PM, Daniel Marcelino <dmsilva.br@gmail.com> wrote:
> Dear all,
>
> I'm dealing with a large data set which one string var is completely
> nested. I easily take off numbers from it, but I still breaking my
> head trying to figure out how can I get from var words like "PP",
> "Deputado Federal", "Senador", "Deputado Estadual". So, below a paste
> few cases.
>
> clear
> inp str200 var1
> "155 - VITAL DO REGO FILHO - PB - Senador"
> "1111 -  - PP -  - Deputado Federal / 25888 - ATAIDES MENDES PEDROSA -
> PB - Deputado Estadual"
> "1111 -  - PP -  - Deputado Federal / 22333 - EDNALDO PEREIRA DE
> SANTANA - PB - Deputado Estadual"
> "151 - JOSE WILSON SANTIAGO - PB - Senador"
> "45123 - ANTONIO HERVAZIO BEZERRA CAVALCANTI - PB - Deputado Estadual"
> "1212 - DAMIÃO FELICIANO DA SILVA - PB - Deputado Federal"
> end
>
> gen var2 = regexs(0) if regexm(var1, "^[0-9a-zA-Z]*")
>
> *
> *   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/


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