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]
Re: st: -args- how to flag when missing or too many arguments
From
John Antonakis <[email protected]>
To
[email protected]
Subject
Re: st: -args- how to flag when missing or too many arguments
Date
Thu, 21 Mar 2013 22:58:43 +0100
Thanks! Giving 5 numbers instead of 4 displays the error I want.
However, missing a number still displays the default error:
<0 invalid name
instead of what I wanted displayed.
Any other ideas?
Best,
J.
__________________________________________
John Antonakis
Professor of Organizational Behavior
Director, Ph.D. Program in Management
Faculty of Business and Economics
University of Lausanne
Internef #618
CH-1015 Lausanne-Dorigny
Switzerland
Tel ++41 (0)21 692-3438
Fax ++41 (0)21 692-3305
http://www.hec.unil.ch/people/jantonakis
Associate Editor
The Leadership Quarterly
__________________________________________
On 21.03.2013 22:49, daniel klein wrote:
John,
I think I would address this with something like this
cap pr drop john
pr john
vers 12.1
args a b c d
if !inrange(`: word count `0'', 1, 4) {
di as err "Please enter data after " ///
"the command john as follows: vars df N chi"
e 198
}
numlist "`0'" ,int r(>0)
end
Best
Daniel
--
Hi:
I am writing a program and would like Stata to return an error if an
argument is missing or there are too many of them.
For example, if an argument is not an integer, the below will return an error:
program define john, rclass
version 12
args no_vars df N chi
if `no_vars'<0 | `df'<0 | `N'<0 | `chi'<0 {
di in red "You have to use integers."
exit 498
}
end
Now, how do I make Stata display:
di in red "Please enter data after the command john as follows: vars df N chi"
.....in cases where (a) there is a missing value (i.e., the user
missed putting 4 numbers) and (b) if the user provides too many
numbers (i.e., 5 instead of 4).
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/