I am working with binary variables that take the values 0 or 1. I
would like to generate the weighted number of observations that are
equal to 1. The number obtained with -tabstat- is different from that
obtained with -tab- or -collapse-. How can this difference be
explained?
. sysuse auto, clear
. label drop origin
. tab foreign
Car type | Freq. Percent Cum.
------------+-----------------------------------
0 | 52 70.27 70.27
1 | 22 29.73 100.00
------------+-----------------------------------
Total | 74 100.00
. tabstat foreign, stat(sum)
variable | sum
-------------+----------
foreign | 22
------------------------
So far, so good, the unweighted number of observations=1 is the same.
Now let's add a weight.
. tab foreign [aw=weight]
Car type | Freq. Percent Cum.
------------+-----------------------------------
0 | 57.1261189 77.20 77.20
1 | 16.8738811 22.80 100.00
------------+-----------------------------------
Total | 74 100.00
. tabstat foreign [aw=weight], stat(sum)
variable | sum
-------------+----------
foreign | 50950
------------------------
According to -tab-, the weighted number of observations=1 is about
16.9. According to -tabstat-, the number is 50950. With -collapse- we
get the same result as with -tab-.
. collapse (sum) foreign [aw=weight]
. clist, noobs
foreign
16.8739
Should the results obtained with -tab-, -tabstat-, and -collapse- not
be the same? Many thanks for your comments.
Friedrich Huebler
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/