Statalist


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

st: RE: egen & sum()


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: egen & sum()
Date   Wed, 26 Nov 2008 11:01:43 +0100

Line for the server...

See - help whatsnew8to9- and search for "sum()"

"The following egen functions have been renamed:

                old name    new name
                ------------------------
                any()       anyvalue()
                eqany()     anymatch()
                neqany()    anycount()
                rfirst()    rowfirst()
                rlast()     rowlast()
                rmean()     rowmean()
                rmin()      rowmin()
                rmiss()     rowmiss()
                robs()      rownonmiss()
                rsd()       rowsd()
                rsum()      rowtotal()
                sum()       total()
                ------------------------"


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Neil Shephard
Sent: Wednesday, November 26, 2008 10:52 AM
To: [email protected]
Subject: st: egen & sum()

Hi,

I've been poring over someone else's Stata code trying to understand it
and have discovered what seems to be inconsistent or undocumented behaviour.

The do-file has the following line...

egen b = sum(a)

This stood out to me as I thought the current version of -egen- uses the
-total()- function to obtain the combined (as opposed to running) sum of
a variable so checked the -man egen- and -man egenmore- pages and sure
enough there is no mention of -sum() as an -egen- function.

-sum()- is however a [P] function and returns the running sum of the
specified variable.

Thus I would have expected -egen b = sum(a)- to return the running sum
of b, but this is not the case, it behaves as though -sum()- is a
synonym for -total()- as the following example demonstrates...

. clear

. set obs 10
obs was 0, now 10

. gen a = _n

. gen b = sum(a)

. egen b2 = sum(a)

. egen b3 = total(a)

. list

     +-------------------+
     |  a    b   b2   b3 |
     |-------------------|
  1. |  1    1   55   55 |
  2. |  2    3   55   55 |
  3. |  3    6   55   55 |
  4. |  4   10   55   55 |
  5. |  5   15   55   55 |
     |-------------------|
  6. |  6   21   55   55 |
  7. |  7   28   55   55 |
  8. |  8   36   55   55 |
  9. |  9   45   55   55 |
 10. | 10   55   55   55 |
     +-------------------+

Based on the help-pages and documentation I would have expected b2 == b1
as -egen b2 = sum(a)- should be treating -sum()- as described in the
-man sum()- page.  Indeed even the third example in -man egen- shows
that -sum()- should be used with -generate- and -total()- should be used
with -egen-

Is there any historical legacy that anyone is aware of -sum()- being a
valid -egen- function that may be lingering around causing this behaviour?

Should the behaviour or the documentation be modified?

Or have I completely misunderstood things?

Neil

-- 
"We should make things as simple as possible, but not simpler" - Anon (not
Albert Einstein)


***********************************************************************
This  message  may  contain  confidential and  privileged  information.
If you  are not the  intended recipient  you should not  disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents.  To do so is strictly  prohibited and may be unlawful.
Please  inform  the  sender that  this  message has  gone astray before
deleting it.  Thank you.

2008 marks the 60th anniversary of the NHS.  It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS  and  would like  an NHSmail  email account, go
to: www.connectingforhealth.nhs.uk/nhsmail
***********************************************************************

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