[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Programming sub-routines
Before coming to Stata my programming was honed using Pascal and I'm
missing some of the tricks I used to access there. I would appreciate
any advice on a particular problem I have with Stata sub-routines.
I'm used to being able to modularise my programs (in Pascal) by having
lots of sub-routines for repetitive tasks, particularly functions
which carry out some kind of transformation. Some old database
languages (such as DBase) used to allow "user-defined" functions
for similar tasks.
I've tried to find the equivalent in Stata, but to no avail. 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, and
also requires lots of dropping of global macros on exit etc.
Am I missing something obvious? In Pascal terms arguments could be
"val" or "var" (the latter allowing for a return value). But in Stata all
arguments appear to only be "val". Is this right? Do I have any other
options? Any advice would be most appreciated.
University of Sydney
Phone: 02 9351 5622
Fax: 02 9351 5615
* For searches and help try: