Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Re: Varname default in a program
From
Dani Tilley <[email protected]>
To
stata <[email protected]>
Subject
st: Re: Varname default in a program
Date
Fri, 9 Jul 2010 11:41:53 -0700 (PDT)
Thanks Nick.
----- Original Message ----
I don't think there is a way to do this with -syntax- but that doesn't
matter.
Within your program, after your -syntax- statement you go
if "`pvar'" == "" local pvar "<default>"
as if -pvar()- was not selected, the local macro pvar will be empty. Or,
rather, the local macro pvar will be undefined, but that's the same to
Stata.
By the way, the -help- for -syntax- should be considered complete, so
guessing that there are undocumented extras is not a good strategy.
Nick
[email protected]
From: Dani Tilley <[email protected]>
To: stata <[email protected]>
Sent: Fri, July 9, 2010 2:16:13 PM
Subject: Varname default in a program
Hi,
I'm trying to write a program that will have the following syntax
syntax varlist(min=1 max=5), [Pvar(varname)]
However, I want the to have a default value for pvar so that when users say
-command var1 var2- the program returns no error and uses the default variable
for pvar. I know how this is done for numeric variables but can't do it in this
context. I tried [Pvar(varname default)] where default is a variable but got
r(197).
Any help is appreciated.
DF Tilley
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/