<>
Another aspect to this issue is that counts are more easily obtained via
-contract- which features a -zero- option. As it turns out, though, the -if-
qualifier is evaluated first, and the -zero- option only pertains to the
combinations of the -varlist- supplied to -contract-, not to the existence
of any variables to work on...
*************
sysuse auto, clear
sum price
contract mpg /*
*/ if price < `r(min)', /*
*/ zero
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Neil Shephard
Gesendet: Freitag, 2. Oktober 2009 12:30
An: [email protected]
Betreff: st: -collapse- with no observations?
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 - [email protected]
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/
*
* 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/