Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: bug in "egen" command?


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: bug in "egen" command?
Date   Fri, 26 Sep 2008 14:13:56 +0200

Is "pid" the same as "id"? And what is the connection to the -tsset-
command? Is the problem w/o -tsset-ing not exactly the same?


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Rembert De
Blander
Sent: Friday, September 26, 2008 4:27 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: bug in "egen" command?

The problem can be stated as follows:

Consider the panel data setting where the command

<<tsset pid time>>

was issued. Under these circumstances, the command:

<<by pid: egen double i`x' = mean(`x')>>

should be exactly identical to:

<<
  generate double I`x' = 0
  qui levelsof `id', local(idlst)
  foreach lvl of local idlst {
  qui summarize `x' if (`id' == `lvl'), meanonly
  qui replace I`x' = r(mean) if (`id' == `lvl')
  }
>>

Now, the problem, as far as I experienced it, can appear when `x' is a
float variable. Worse, the discrepancy between both command sequences
seems to involve a "random" component, since it differs from run to run.
The latter sequence of commands always produces identical results, but the
'egen' commands output varies. Of course these fluctuations are of the
order of machine precision. Nevertheless they are worrying, since they
constitute 'unexpected' and certainly undocumented behaviour, which can
lead to substantial differences, especially in iterated procedures.

The problem does not occur for any `x', but I have a dataset & sequence of
commands that produce the described behaviour.

Since I am not allowed to post attachments, please mail me for more info:

Rembert_at_DeBlander.eu


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index