Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: a question about local macro


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: a question about local macro
Date   Fri, 11 Nov 2005 17:08:48 -0000

Radu is correct. 

And there is a way round it. You 
can use -c_local-. -c_local- is not 
documented; it is not even "undocumented" 
(-help undocumented-). So, how does anyone 
outside StataCorp know about it? 

What happens is this: after a long period
of Stata use in which you have done well, 
Stata will speak to you: 

"Greetings! You have reached the seventh 
level of Stata, and I name you Statafriend. 

You will now be initiated into seven
Stata secrets. The first is -c_local-." 

and so forth, but the rest of it is
probably not of interest. 

Anyway, 

. c_local IC "IC412 IC413" 

will do what you want. Think of it as 
inserting the named local in the 
calling program's namespace. Often 
you will want a double allocation: 

. local IC "IC412 IC413" 
. c_local IC "IC412 IC413" 

Now be warned: 

1. -c_local- flouts much computing thinking and would 
often be regarded as very bad programming space. 

2. That is not just a purist sense of high 
and good style. -c_local- can mess up your 
programs. If, and only if, you understand 
that and how it causes problems, you should
feel free to use it. (Mind you, globals can
do harm as well!) 

Nick 
[email protected] 

Radu Ban
 
> this is because the local macro is defined in the do-file and NOT in
> the current Stata session. so when you try to access the local macro
> from the Stata session, Stata doesn't have anything stored in `IC',
> hence it evaluates to empty.
 
 
Jian Zhang 

> > I have a question about the local macro.  I could not 
> figure out why and
> > how to get around it.  Hope that you can help me out.
> >
> > Here is the question.  In my do file, I have two commands 
> as follows:
> >
> > local IC="IC412 IC413"
> > reg y `IC'
> >
> > The question is that when I run the two commands together
> > it works.  But I found that if I then re-run the second 
> command without
> > running the first command,  I thought it should give the 
> same results
> > since i have already defined the local macro, so I do not need to
> > redefine it.  It turns out that this time stata treated 
> `IC' as empty.
> > That means if I want to run the second command,  i always 
> need to run the
> > two commands together.  Am I correct?  Any explanations? Is 
> there anyway
> > to get around this?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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