[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Programming question
> If you write:
> program define myprog
> version 7
> syntax [varlist]
> Stata validates the list of the variable names passed by the user and
> complains if a variable does not exist e.g.
> . myprog unknownvar
> variable unknownvar not found
> However, the insheet internal command apparently allows the user
> to enter a
> list of names for non-existing variables without a problem. Is it possible
> to do the same thing from an ado command? And how?
You can do this in several ways.
In general, you are not obliged to use -syntax-
in a program. You could use -gettoken- or -args-
or some other method to work with your input
or indeed rely on Stata's default parsing.
For example with
program def myprog
di "first argument is `1'"
di "second argument is `2'"
the first argument supplied will be -display-ed
and _could_ be used in some way. Here the program (and indeed Stata) neither
knows nor cares what "unknownvar" is: it is just a character string.
With -syntax- you could use
With the latter two, you are _not_ obliged to create a new variable.
All that happens is frontier control: Stata affirms that what is
presented as a newvarname when you enter the program is not, at
that point, the name of an existing variable and would be a legal
name for a new variable. What you do thereafter is up to you.
* For searches and help try: