Statalist


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

Re: st: Errors in egen, total()


From   Sven-Oliver Spieß <[email protected]>
To   [email protected]
Subject   Re: st: Errors in egen, total()
Date   Sun, 13 Dec 2009 15:38:28 +0100

Hi Mike,

my guess it that it's a rounding problem because of different data
types. I was able to reproduce your problem in section B below. Try to
declare your cumrev-variable to be long instead of floating point (C).

     ---Beginning example:---
     preserve

     *A: Both float
     input str1 title week rev
     A 707 28536717
     A 708 10
     A 708 20
     end

     bys title week: egen cumrev=total(rev)

     format rev cumrev %9.0f

     list


     *B: Rev long, cumrev float
     clear
     input str1 title week long rev
     A 707 28536717
     A 708 10
     A 708 20
     end

     bys title week: egen cumrev=total(rev)

     format rev cumrev %9.0f

     list


     *C: Both long
     clear
     input str1 title week long rev
     A 707 28536717
     A 708 10
     A 708 20
     end

     bys title week: egen long cumrev=total(rev)

     format rev cumrev %9.0f

     list

     restore
---End example---


Type 'help data_types' for more information.


Cheers,
Sven-Oliver


On Sun, Dec 13, 2009 at 05:19, Mike Kim <[email protected]> wrote:
> Hello all,
>
> I used "egen total()" to create "cumrev" like the following, but if there is
> only one week per title, total gives a slightly lower number than the
> original number in some cases (1 or 2 lower). Any idea about why it produces
> different numbers?
>
> bys title week: egen cumrev=total(rev)
>
> title   week    rev                 cumrev
> A       707     28536717     28536716
> A       708     10                   30
> A       708     20                   30
> B        801    .....
> ......
>
> Thank you,
> Mike.
>
> *
> *   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