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

RE: st: Programming sub-routines

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Programming sub-routines
Date   Wed, 3 Nov 2004 22:21:24 -0000

In many circumstances, I find -c_local- a useful 
alternative. -c_local- is not documented but 
is used quite frequently in StataCorp programs, 
as a -grep- or equivalent of the official ado 
files will show. 

In practice, fair criteria of whether you 
should use -c_local- are that 

1. you can work out from examples what the 
syntax is and what it does 

2. you can also work out why it means that 
you can mess up your own programs 

3. it looks appropriate to your problem. 

[email protected] 

Nick Winter
> You should read up on saving results in [U] 21.10.
> The short version is that for returning value(s), usually you 
> do an rclass program:

Ian Watson 

> >If I use
> >a sub-routine inside a main program I can pass it arguments no
> >problem. But after doing some transformations on the 
> arguments, how can I
> >send the results back to the main program? If I declare new local
> >macros to store the results, they disappear when I return to the main
> >program (because they're no longer in scope). If I declare global
> >macros, I can access the results back in the main program, but I'm
> >left with a lot of global macros. This appears to me bad 
> practice, andalso requires lots of dropping of global macros on exit etc.
> >

*   For searches and help try:

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