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
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
RE: st: Assigning values from a list
Date
Fri, 21 May 2010 17:04:10 +0100
I was just tweaking Maarten's code, not yours. That does not undermine your point, which I have had occasion to emphasise elsewhere.
Nick
[email protected]
Austin Nichols
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/
*
* 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/