Statalist


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

st: -collapse- with no observations?


From   Neil Shephard <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: -collapse- with no observations?
Date   Fri, 2 Oct 2009 11:30:29 +0100

Hi,

I've encountered some unexpected behaviour whilst using -collapse- on
different subsets of data.  An example to demonstrate the problem....

sysuse auto, clear
sum price
collapse (count) n = mpg if(price < 2000)

This results in an error as there are no cars with price < 2000...

. sysuse auto, clear
(1978 Automobile Data)

. sum price

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       price |        74    6165.257    2949.496       3291      15906


. collapse (count) n = mpg if price < 2000
no observations
r(2000);

I would have expected the command to run and return a count of zero
(0) as this is a valid number of counts (to my mind at least).

There's a mention at http://www.stata.com/help.cgi?whatsnew10 that
indicates that trying to open the data editor with an if qualifier
that resulted in zero observations used to cause Stata to crash, but
that has been fixed.

Searching the archives/FAQ I haven't been able to find whether this
has has been discussed before, or is a reasonable behaviour (as I say
I would have expected to get a count of zero returned).

Neil

-- 
"The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data." ~ John Tukey (1986), "Sunset salvo". The American
Statistician 40(1).

Email - nshephard@gmail.com
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index