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: Extract identifier in the middle of a string variable


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Extract identifier in the middle of a string variable
Date   Fri, 14 Dec 2012 13:19:56 +0000

I tried various solutions with -moss- (SSC) but kept messing up the
regular expression. Robert Picard is more fluent than I with regexp.

Here is a more simple-minded approach:

clear
input str80 myid
"BASE:C;  BAYB:C;  BMV:C *;  BST:TRVC;  BVL:C;  DB:TRVC;  NYSE:C.PRH;"
"NYSE:C;  NYSE:C.PRI;  SOMA:CTGP11B;  TSE:8710;  XTRA:TRV"
end
gen wc = wordcount(myid)
gen nyse = ""
su wc, meanonly
qui forval i = 1/`r(max)' {
	replace nyse = nyse + substr(word(myid, `i'), 6, .) + " " if
substr(word(myid, `i'), 1, 4) == "NYSE"
}
replace nyse = trim(subinstr(nyse, ";", "", .))
split nyse
local nsplit : word count `r(varlist)'
gen shortest = nyse1
qui forval i = 2/`nsplit' {
	replace shortest = nyse`i' if length(nyse`i') < length(shortest) &
length(nyse`i')
}


On Fri, Dec 14, 2012 at 12:46 PM, Ghislaine Vantomme
<[email protected]> wrote:
> BASE:C;  BAYB:C;  BMV:C *;  BST:TRVC;  BVL:C;  DB:TRVC;  NYSE:C.PRH;
> NYSE:C;  NYSE:C.PRI;  SOMA:CTGP11B;  TSE:8710;  XTRA:TRV
>
>
*
*   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