Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Puzzled by behavior of -recode varlist (.a/.z=.)-

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Puzzled by behavior of -recode varlist (.a/.z=.)-
Date   Fri, 23 Apr 2004 19:29:07 +0100

But .a etc. are being compared as string equivalents, 
".a" etc., presumably because of this behaviour of -inrange()- 
with numeric missings. And it makes sense to ask 
whether some string lies between ".a" and ".z"
in ASCII order. 

[email protected] 

Richard Williams
> Definitely sounds like odd behavior to me.  Looking at 
> -recode.ado-, I 
> notice there are these lines:
>          else if length(`"`v'"')==2  &  inrange(`"`v'"',".a",".z") {
>                  return local s1 `v'
> Now, I haven't waded through the whole ado file, but I wonder 
> if that line 
> is doing what it is supposed to do.  According to the online 
> docs for inrange,
>      "inrange(z,a,b) returns 1 if it is known that a <= z <= 
> b; otherwise, 
> this function returns 0.  If z = missing (.) this function 
> returns 0.  For 
> numeric arguments, if a = missing and/or b = missing these values are 
> interpreted as a = -infinity and/or b = +infinity, respectively."
> Now, I just tried the command
> . gen z = inrange(var1, .a, .z)
> where var1 was a mixture of missing and nonmissing values, 
> and z = 0 for 
> every case.  This is consistent with the docs saying "If z = 
> missing (.) 
> this function returns 0" but it is not consistent with what the users 
> intent would probably be in this case.
> Anyway, it is hard for me to believe that this is not a bug, 
> and my wild 
> guess is that it might have something to do with the use of 
> the inrange 
> command as shown above.  But, it could be something else.

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index