Statalist


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

AW: AW: st: AW: Diffrence between sum and tabsum


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: AW: st: AW: Diffrence between sum and tabsum
Date   Tue, 15 Sep 2009 14:54:00 +0200

<> 

For instance, the line

*************
tab dummy, sum(firstweight)
*************

returns



	Summary	of firstweight
dummy	Mean	Std. Dev.	Freq.
			
1	13949.146	.00021143	3
			
Total	13949.146	.00021143	3


for me. The sd differs from yours...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Ulrich Kohler
Gesendet: Dienstag, 15. September 2009 14:43
An: [email protected]
Betreff: Re: AW: st: AW: Diffrence between sum and tabsum

Am Dienstag, den 15.09.2009, 13:45 +0200 schrieb Martin Weiss:
> <> 
> 
> Also note http://www.stata.com/support/faqs/data/float.html

Well, yes I know that. But I still don't think that this satisfactorily
explains the values.

> I get answers different from yours, both in Stata 10.1 and 11, 

What do you mean that you get different answers. Do you get a zero? 

> possibly b/c your dataset is not created by the code that you showed in
your reply? 
> I assume this is the case as your -list- command shows the "dummy"
> although it is -generate-d in the following line... 

The dataset is created as described. I just produced the output of
-list- later and copied it to a place where I (mistakenly) thought it
makes things clearer.

Here is one more tackle on that. The first lines of the following
do-file reproduces the behavior on more time. The second part calculates
the standard deviation  "by hand" showing that one could circumvent the
problem described in the FAQ. The third part changes one bit in the
hand-made solution, which makes it coming quite close to the -tabsum-
solution. 

However, I have expected that -tabsum- works like the second part. 

---------------------------------------------------------11.do
clear
set obs 3
gen byte coreweight1968 = 18
gen double firstweight =   coreweight1968  *  60468000/78028
gen dummy = 1
tab dummy, sum(firstweight)

gen double sum = sum(firstweight)
gen double mean = sum[_N]/3
gen double diff = sum((firstweight - mean)^2)
di %17.16f sqrt(diff[_N]/2)

drop sum-diff
gen float sum = sum(firstweight)
gen double mean = sum[_N]/3
gen double diff = sum((firstweight - mean)^2)
di %17.16f sqrt(diff[_N]/2)

----------------------------------------------------------------

Here is the output of the do-file without any modifications.

. do 11

. clear

. set obs 3
obs was 0, now 3

. gen byte coreweight1968 = 18

. gen double firstweight =   coreweight1968  *  60468000/78028

. gen dummy = 1

. tab dummy, sum(firstweight)

            |       Summary of firstweight
      dummy |        Mean   Std. Dev.       Freq.
------------+------------------------------------
          1 |   13949.146   .00024815           3
------------+------------------------------------
      Total |   13949.146   .00024815           3

. 
. gen double sum = sum(firstweight)

. gen double mean = sum[_N]/3

. gen double diff = sum((firstweight - mean)^2)

. di %17.16f sqrt(diff[_N]/2)
0.0000000000022278

. 
. drop sum-diff

. gen float sum = sum(firstweight)

. gen double mean = sum[_N]/3

. gen double diff = sum((firstweight - mean)^2)

. di %17.16f sqrt(diff[_N]/2)
0.0007678068963647

. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
end of do-file





*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index