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]

Re: st: macro problem


From   Richard Goldstein <richgold@ix.netcom.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: macro problem
Date   Mon, 11 Jun 2012 11:58:40 -0400

you don't make it clear about what doesn't work

but here is a guess: you are getting match=1 in all cases (or at least
all where strvar is not missing); remember, however, that strpos=0 if
"S" is not found; so, in addition to the quotes, etc., I guess you want
to ensure that strpos is >0 (and maybe <.)

Rich

On 6/11/12 11:50 AM, Jeph Herrin wrote:
> This should be trivial, but for some reason I cannot get it.
> 
> I have a string variable, and I have a list of string values I need to
> match against it. There are occasional trailing or leading characters in
> the variable, so I am using -strpos- to find matches. Thus
> 
>   local matchlist "string 1" "string 2"  "string 3" .... "string 55"
> 
>   gen byte match=0
>   foreach S in `matchlist' {
>         replace match = 1 if strpos(strvar,`S')
>   }
> 
> Now, I know I have got the quotes and macro evaluations wrong, but that
> is the problem: I've tried this many different ways, and yet cannot seem
> to find a combination that works. Any thoughts?
> 
> thanks,
> Jeph
*
*   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