Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

-args- [was: RE: st: Arguments in the -ml-]


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   -args- [was: RE: st: Arguments in the -ml-]
Date   Fri, 1 Feb 2008 17:20:49 -0000

There seems to be some confusion here. 

-args- does one, and only one, thing. 

If you type say  

args name1 name2 name3 

then that is equivalent to 

local name1 "`1'" 
local name2 "`2'" 
local name3 "`3'" 

So, it is a convenience command for manipulating local macros. 

How might the need for this arise? 

1. You type some command, say 

foobar x y 42 

Whatever you type after the command name is mapped to local macros 1, 2,
3, etc. under the rules that spaces separate, but double quotes bind
tighter. 
The first "word" in this sense is mapped to macro 1, the second to macro
2, and so forth. 

In this simple example, within -foobar- local macro 1 will contain "x",
local macro 2 will contain "y" and local macro 3 will contain "42". So
within -foobar- you could have some mapping like 

args xvar yvar magic 

which would be eequivalent to 

local xvar "`1'" 
local yvar "`2'" 
local magic "`3'" 

Notice in this example you might have instead 

args xvar yvar magic extra 

which would imply also 

local extra "`4'" 

which in this example would imply that -extra- was created empty (or not
created at all) or, if it already existed, was blanked out (or
destroyed). There is no problem there as far as -args- is concerned, and
this is often a useful kind of flexibility. 

2. You could use -tokenize- followed by -args-. If I went 

tokenize "x y 42" 
args xvar yvar magic 

then that has similar effect. -tokenize- overwrites any previous
assignment to local macros 1, 2, 3, etc. The "etc." here bites: in this
example, any local macros 4, 5, etc. will also be overwritten, meaning
blanked out. That underscores the usefulness of -args- in getting
informative stuff out of numbered macros as soon as possible. 

3. You could do something like this: 

local 1 "x" 
local 2 "y" 
local 3 "42" 
args xvar yvar magic 

It is hard to see why you might want to do that, but it's legal. 

Now, notice two key things that have not been said. 

* -args- has no special link to -ml-. 

* -args- has no other side-effects for -ml- or indeed any other command.

Once macros have been assigned, what you do with them in what order is
up to you (and the rest of Stata syntax). 

Also, remember what a local macro is. If I have some other command and I

feed some macros to it, say 

buzzwuzz `yvar' `xvar' `magic' 

-buzzwuzz- doesn't even know that what is being fed to it consists of
local macros, because those macros will have been substituted with their
contents (if any) by Stata before -buzzwuzz- ever gets to work. So there
is cosmic indifference on the part of any other program such as
-buzzwuzz- to the order in which macros have been defined: it doesn't
care in practice, and it hasn't even the notionof caring in principle. 

Nick 
n.j.cox@durham.ac.uk 

P.S. Keeping your program tidy and easy to follow is important, but a
completely different issue. 



Mentzakis, Emmanouil

[...] 
 
So, the order in -args- should follow the order in -lnf-  which should
follow the order in -ml model-. Would this be a foolproof procedure to
follow? 
 
[...] 

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