Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: -args- how to flag when missing or too many arguments

From   John Antonakis <>
Subject   st: -args- how to flag when missing or too many arguments
Date   Thu, 21 Mar 2013 22:13:36 +0100


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

Now, how do I make Stata display:

di in red "Please enter data after the command john as follows: vars df N chi" 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).



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
Tel ++41 (0)21 692-3438
Fax ++41 (0)21 692-3305

Associate Editor
The Leadership Quarterly

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index