Dear All,
is this a bug in Stata?
sysuse auto
.MyObject=.object.new
summarize price
.MyObject Declare double AvPrice1 = r(mean)
.MyObject Declare double AvPrice2 = 6165.256756756757
classutil des .MyObject
Output:
object .MyObject:
classwide:
dbstyle .dbstyle
.Declare:
double .AvPrice1 = .
double .AvPrice2 = 6165.256756756757
I expected .MyObject.AvPrice1 to be identical to .MyObject.AvPrice2.
It seems that -Declare- destroys the r()-saved results and causes
incorrect object's field initialization to a missing.
In particular, -Declare- saves to the r() results the macros "key" and
"name", which accidentially could be the ones that the user attempts
to initialize with, e.g. Then the field will be initialised to a
"__key(memory address)" or "newfieldname" correspondingly, which is
not what was intended. The problem is hard to find, since Declare is a
built-in procedure and does not show up in -trace-.
Current workaround seems is to assign the r() result to a temporary
local, then initialize the field.
summarize price
local avprice=r(mean)
.MyObject Declare double AvPrice3 = `avprice'
Or declare the field in one statement and initialize in another, like so:
.MyObject Declare double AvPrice4
summarize price
.MyObject.AvPrice4 = r(mean)
(also submitted to tech-support)
Thank you,
Sergiy Radyakin
*
* 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/