Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Question about scalars


From   Jeph Herrin <stata@spandrel.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Question about scalars
Date   Mon, 09 Aug 2010 15:26:44 -0400

Yes, but look closely at

> . scalar e = d + a
> . scalar dir a d e // "e" is wrong
>           a =         10
>           d =  4.9458042
>           e =        131

You'll see that 4.94+10 = 131. Which is incorrect.

cheers,
Jeph

On 8/9/2010 2:15 PM, Sergiy Radyakin wrote:
Hi, Steve,

there might be something else in your program that prevents it from
running. Both code fragments that you compare work fine in my Stata 9
and Stata 11.

Best, Sergiy

. do "R:\TEMP\STD0h000000.tmp"

. clear

. scalar drop _all

. scalar a = 10

. scalar b = 20

. scalar c = b + a

. scalar dir
          c =         30
          b =         20
          a =         10

.
. sysuse auto, clear
(1978 Automobile Data)

. reg mpg foreign

       Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  1,    72) =   13.18
        Model |  378.153515     1  378.153515           Prob>  F      =  0.0005
     Residual |  2065.30594    72  28.6848048           R-squared     =  0.1548
-------------+------------------------------           Adj R-squared =  0.1430
        Total |  2443.45946    73  33.4720474           Root MSE      =  5.3558

------------------------------------------------------------------------------
          mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      foreign |   4.945804   1.362162     3.63   0.001     2.230384    7.661225
        _cons |   19.82692   .7427186    26.70   0.000     18.34634    21.30751
------------------------------------------------------------------------------

. scalar d = _b[foreign]

. scalar e = d + a

. scalar dir a d e // "e" is wrong
          a =         10
          d =  4.9458042
          e =        131

.
. tempname dd

. scalar `dd' = _b[foreign]

. scalar e = `dd' +a

. scalar dir a `dd' e // "e" is /okay
          a =         10
   __000000 =  4.9458042
          e =  14.945804

.
end of do-file


On Mon, Aug 9, 2010 at 1:57 PM, Steve Samuels<sjsamuels@gmail.com>  wrote:
In the code below, I generate a scalar "d" from a regression result;
it looks okay, but trying to add it to another scalar doesn't work.
If, however I use a -tempname- , I get the right answer.  Could
someone explain to me why the first approach doesn't work and if
there's another approach that doesn't involve a -tempname-?

Thanks,

Steve

******************************
clear
scalar drop _all
scalar a = 10
scalar b = 20
scalar c = b + a
scalar dir

sysuse auto, clear
reg mpg foreign
scalar d = _b[foreign]
scalar e = d + a
scalar dir a d e // "e" is wrong

tempname dd
scalar `dd' = _b[foreign]
scalar e = `dd' +a
scalar dir a `dd' e // "e" is /okay
****************************

--
Steven Samuels
sjsamuels@gmail.com
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax:    206-202-4783

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index