Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Looping over a levelsof macro to match/replace


From   Andrew Back <andrewback@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Looping over a levelsof macro to match/replace
Date   Mon, 16 Apr 2012 15:16:33 -0400

I have two string variables: ticker and tickerlist.

"tickerlist" is a master list of all symbols; "code" is the list of
corresponding issuer codes. These pairs of ticker symbols and codes do
not currently parse with the rest of the dataset:

ticker      issuer_code     tickerlist       code
AAII        .                       A               4215
AAII        .                       AA             42
AAII        .                       AACC        4855
AAII        .                       AACE        2344
AAII        .                       AAI            2755
AAII        .                       AAII           1605

and so on. Ticker is a subset of tickerlist, so what I'm trying to do
is tell Stata to populate the issuer code for each ticker in the rest
of the dataset based on these "tickerlist-code" pairs. In otherwords,
every time Stata sees a ticker symbol I want it to find the
appropriate match in tickerlist and then supply the corresponding code
to fill in the missing data:

levelsof tickerlist, c local(tickerlist)
foreach 1 of local tickerlist {
     replace issuer_code=code if (strmatch(ticker,"`1'")==1)
}

Any thoughts on why this doesn't work would be greatly appreciated. Thanks!

Best,
Andrew Bäck

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index