Statalist


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

st: Local macro variable and do file execution


From   Susheel Patil <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: Local macro variable and do file execution
Date   Wed, 15 Jul 2009 14:47:54 -0400

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index