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: Assigning values from a list


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Assigning values from a list
Date   Fri, 21 May 2010 10:15:47 -0400

Nick--
Thanks for re-emphasizing the integer comparison point.  Also, I was
assuming the list of codes might be quite long (possibly 255+ codes),
but the list of variables that could hold those codes is small (maybe
more than 4, but fewer than 255), which is why I reversed the
comparison shown below.  I.e. I prefer stepping through

inlist(`code',var1,var2, etc.)

to a single long

inlist(var1,`codelist')|inlist(var2,`codelist')|etc.

since my approach is robust to having a codelist with 255 or more
elements. Also, it's far from clear to me that you would want to
restrict to nonmissing varX, since a missing value might indicate no
diagnosis, or no third diagnosis, or what have you.  Perhaps the
original poster can clarify what var3<. and var4==. would mean.

On Fri, May 21, 2010 at 7:23 AM, Nick Cox <[email protected]> wrote:
> Maarten's code can be tweaked further.
>
> As Austin Nichols emphasised testing decimals for equality is a recipe for difficulty if not disaster. Work with integers instead
>
> In addition the | operator can be used to streamline
>
> gen byte virus = (                        ///
>                 inlist(var1, `list') +   ///
>                 inlist(var2, `list') +   ///
>                 inlist(var3, `list') +   ///
>                 inlist(var4, `list')     ///
>                 ) > 1                    ///
>                 if !missing(var1, var2, var3, var4)
>
> to
>
> gen byte virus = inlist(var1, `list') |   ///
>                 inlist(var2, `list') |   ///
>                 inlist(var3, `list') |   ///
>                 inlist(var4, `list')     ///
>                 if !missing(var1, var2, var3, var4)
>
> (I guess > 1 was a typo for > 0.)
>
> Nick
> [email protected]
>

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