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: bug in -xtile-


From   [email protected] (Xiao Yang, StataCorp)
To   [email protected]
Subject   Re: st: bug in -xtile-
Date   Fri, 01 Feb 2013 15:47:57 -0600

Yu Chen <[email protected]> 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 <[email protected]> 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
[email protected] 
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index