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: Looping over a levelsof macro to match/replace


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Looping over a levelsof macro to match/replace
Date   Mon, 16 Apr 2012 20:38:06 +0100

You say this doesn't work but don't explain what that means in your
case, i.e. what doesn't happen that should, or does happen that
shouldn't. But it doesn't seem that you need any kind of matching here
other than strict equality.

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

Nick

On Mon, Apr 16, 2012 at 8:16 PM, Andrew Back <[email protected]> wrote:
> 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!
>

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