Statalist


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

RE: st: Local macro variable and do file execution


From   Susheel Patil <spatil@jhmi.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Local macro variable and do file execution
Date   Wed, 15 Jul 2009 15:45:21 -0400

Many thanks - this explains it.

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eric A. Booth
Sent: Wednesday, July 15, 2009 2:54 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Local macro variable and do file execution

http://www.stata.com/statalist/archive/2008-09/msg00979.html

http://www.stata.com/statalist/archive/2005-11/msg00397.html


On Jul 15, 2009, at 1:47 PM, Susheel Patil wrote:

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