I suspect it's a design decision to accommodate the fact that you
could be trying to sum a combination of non-missing and missing values
e.g. if row 8 had the value of 40 instead of missing. You would
probably(?) want to see the value 40 in the collapsed data set.
You can differentiate between the zeroes in David's example by using
the count function.
. collapse (sum) x (count) n=x, by(group)
. list
+----------------+
| group x n |
|----------------|
1. | 1 33 3 |
2. | 2 63 3 |
3. | 3 0 0 |
4. | 4 0 2 |
+----------------+
On Wed, Feb 10, 2010 at 12:20 PM, Michael Mitchell
<[email protected]> wrote:
> Greetings
>
> I am befuddled by the following example that uses the -collapse-
> command with the -(sum)- function...
>
> . clear
>
> . input group x
>
> group x
> 1. 1 10
> 2. 1 11
> 3. 1 12
> 4. 2 20
> 5. 2 21
> 6. 2 22
> 7. 3 .
> 8. 4 .
> 9. 4 .
> 10. end
>
> .
> . collapse (sum) x , by(group)
>
> . list
>
> +------------+
> | group x |
> |------------|
> 1. | 1 33 |
> 2. | 2 63 |
> 3. | 3 0 |
> 4. | 4 0 |
> +------------+
>
> Shouldn't the value of -x- for groups 3 and 4 be missing, not zero.
> To me, the sum of a series of missing values is a missing value. I am
> doing a collapse for about 100 variables (100 x values) and need the
> value to be defined as missing (not 0) in such cases. Any ideas?
>
> Thanks,
>
> Michael
>
> *
> * 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/