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 on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: bug in -xtile-


From   xyang@stata.com (Xiao Yang, StataCorp)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: bug in -xtile-
Date   Fri, 01 Feb 2013 15:47:57 -0600

Yu Chen <profyuchen@gmail.com> encountered a bug in the way the -xtile-
command handles the case of the number of observations being less than the
requested number of quantiles.  When the -if- condition is specified, -xtile-
produces results.  When the corresponding observations are dropped, -xtile-
reports an error.

> I think there is a bug in -xtile-. I ran the code below, and I still
> got deciles, but they are incomplete. I would expect missing values
> because there are not enough observations.
>
> sysuse auto,clear
> keep in 1/10
> xtile decile=price if price<5000, nq(10)
> ...
>
> In other words, in the first example I added an if condition, and in
> the second example, I deleted those observations. Why is the result
> different? I think this is an inconsistency in -xtile-.
>
> sysuse auto,clear
> keep in 1/10
> drop if price<5000
> xtile decile=price , nq(10)


Nick Cox <njcoxstata@gmail.com> identified the problem in the -xtile-
command:

> The code for -xtile- includes the test
>
>		if `nquanti' > _N + 1 {
>			di in red "nquantiles() must be less than or " /*
>			*/ "equal to number of observations plus one"
>			exit 198
>		}
>
> but a better test would be something like
> 
> marksample touse
> qui count if `touse'
> 
> if `nquanti' > r(N) + 1 {
> 
> The total number of observations _N is not the right number to check
> against.


This is indeed a bug.  We will fix this in a future update. 


-- Xiao
xyang@stata.com 
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index