Statalist


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

st: RE: AW: Local macro variable and do file execution


From   Susheel Patil <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: AW: Local macro variable and do file execution
Date   Wed, 15 Jul 2009 17:12:36 -0400

Absolutely correct.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Wednesday, July 15, 2009 3:52 PM
To: [email protected]
Subject: st: AW: Local macro variable and do file execution


<>

Eric has pointed you to older threads which have discussed this issue. You
may also want to note that a Stata session - during which you enter commands
in the Command window - counts as one "level", with the result being that
your -local-s are retained until you -ma drop- them... Just enter your
commands one by one in the Command window to see this effect...

HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Susheel Patil
Gesendet: Mittwoch, 15. Juli 2009 20:48
An: '[email protected]'
Cc: Susheel Patil
Betreff: st: Local macro variable and do file execution

Dear All:

I have noticed a rather interesting phenomenon for which I don't have an
explanation. I'm hoping someone might have an answer. I have the following
do file:

sum tmp_dp
local max
display `max'
return list
local max = r(max)
display `max'

If I select a line from the do file and run each line separately, I get the
output below. When I try to display the local macro variable `max'; STATA
tells me it is empty.

. do "C:\DOCUME~1\spatil3\LOCALS~1\Temp\STD06000000.tmp"
. sum tmp_dp

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      tmp_dp |       179    2.888268      1.3897          1          6

. 
end of do-file

. do "C:\DOCUME~1\spatil3\LOCALS~1\Temp\STD06000000.tmp"
. local max
. 
end of do-file

. do "C:\DOCUME~1\spatil3\LOCALS~1\Temp\STD06000000.tmp"
. display `max'

. 
end of do-file

. do "C:\DOCUME~1\spatil3\LOCALS~1\Temp\STD06000000.tmp"
. return list

scalars:
                  r(N) =  179
              r(sum_w) =  179
               r(mean) =  2.888268156424581
                r(Var) =  1.931266084991526
                 r(sd) =  1.389699998198002
                r(min) =  1
                r(max) =  6
                r(sum) =  517

. 
end of do-file

. do "C:\DOCUME~1\spatil3\LOCALS~1\Temp\STD06000000.tmp"
. local max = r(max)

. 
end of do-file

. do "C:\DOCUME~1\spatil3\LOCALS~1\Temp\STD06000000.tmp"
. display `max'

However, when I run the entire do file, STATA tells me `max' is now set to 6
(which is what it should be in my example). Output below.
.

. sum tmp_dp

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      tmp_dp |       179    2.888268      1.3897          1          6

. local max
. display `max'

. return list

scalars:
                  r(N) =  179
              r(sum_w) =  179
               r(mean) =  2.888268156424581
                r(Var) =  1.931266084991526
                 r(sd) =  1.389699998198002
                r(min) =  1
                r(max) =  6
                r(sum) =  517

. local max = r(max)

. display `max'
6 


My question is why is `max' in the 1st situation blank, but in the 2nd
situation assigned a value?

Thanks,

Susheel Patil


-------------------------------------------------------------------
Susheel P. Patil, M.D., Ph.D.
Assistant Professor of Medicine
Johns Hopkins Sleep Disorders Center
Asthma and Allergy Center
5501 Hopkins Bayview Circle, Room 4B.41
Baltimore, MD 21224
 
Phone: 410-550-2335
Fax:410-550-3374
-------------------------------------------------------------------


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