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

 From Ulrich Kohler To statalist@hsphsun2.harvard.edu Subject Re: st: AW: Diffrence between sum and tabsum Date Tue, 15 Sep 2009 13:32:31 +0200

```<>

yes, I thought about that. However, the following bit shows that your
example is not quite the problem here

. set obs 3
. gen byte coreweight1968=18
. gen double firstweight =   coreweight1968 *  60468000/78028
. format firstweight %32.20f
. l

+-----------------------------------------------+
| cor~1968                  firstweight   dummy |
|-----------------------------------------------|
1. |       18   13949.14646024503963417374       1 |
2. |       18   13949.14646024503963417374       1 |
3. |       18   13949.14646024503963417374       1 |
+-----------------------------------------------+

. 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

However you are right that is should be some kind of a precision
problem. In fact

. replace firstweight =   coreweight1968 *  4/3
. tab dummy, sum(firstweight)

works as expected.

Am Dienstag, den 15.09.2009, 12:54 +0200 schrieb Martin Weiss:
> <>
>
>
> Probably a precision issue as in
>
> ***
>
> clear*
>
> inp double firstweight
> 13949.1460454864
> 13949.146248765
> 13949.146324324
> end
>
>
> gen byte dummy=1
>
> su firstweight
>
> tab dummy,  /*
> */ sum(firstweight)
>
> ***
>
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Ulrich Kohler
> Gesendet: Dienstag, 15. September 2009 12:14
> An: statalist
> Betreff: st: Diffrence between sum and tabsum
>
> <>
>
> Does anybody know why -tabulate, summarize- displays a nonzero
> standard-deviation for a variable that is a constant?
>
> . tab seopsu if seopsu==948, sum(firstweight)
>
>      Cps Pr |
>    Sampl Un |       Summary of firstweight
>     5:71-73 |        Mean   Std. Dev.       Freq.
> ------------+------------------------------------
>         948 |   13949.146   .00024815           3
> ------------+------------------------------------
>       Total |   13949.146   .00024815           3
>
> . sum firstweight if seopsu==948
>
>     Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>  firstweight |         3    13949.15           0   13949.15   13949.15
>
> . return list
>
> scalars:
>                   r(N) =  3
>               r(sum_w) =  3
>                r(mean) =  13949.14646024504
>                 r(Var) =  0
>                  r(sd) =  0
>                 r(min) =  13949.14646024504
>                 r(max) =  13949.14646024504
>                 r(sum) =  41847.43938073512
>
> . d firstweight
>
>               storage  display     value
> variable name   type   format      label      variable label
> ----------------------------------------------------------------------------
> ------
> firstweight     double %10.0g
>
> . l firstweight if seopsu==948
>
>       +-----------+
>       | firstwe~t |
>       |-----------|
> 4256. | 13949.146 |
> 4365. | 13949.146 |
> 4537. | 13949.146 |
>       +-----------+
>
>
> Stata/MP 11.0 for Unix (Linux 64-bit x86-64)
> Born 26 Aug 2009
>
>
>
> *
> *   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/

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