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]
st: Looping over a levelsof macro to match/replace
From
Andrew Back <[email protected]>
To
[email protected]
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/