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

From |
Nathan Danneman <ndanneman@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: RE: generate an error message if the wrong number of args is given following the args command |

Date |
Tue, 30 Jun 2009 10:58:37 -0400 |

Nick, thanks for the crafty solution. N On Tue, Jun 30, 2009 at 7:36 AM, Nick Cox<n.j.cox@durham.ac.uk> wrote: > Thanks for this, but also please note the request in the FAQ to close threads publicly. > > Nick > n.j.cox@durham.ac.uk > > > -----Original Message----- > From: Nathan Danneman [mailto:ndanneman@gmail.com] > Sent: 29 June 2009 22:49 > To: Nick Cox > Subject: Re: st: RE: RE: generate an error message if the wrong number of args is given following the args command > > Ah, adding an extra argument, and making sure it is blank. A nice > trick - thanks! > > On Mon, Jun 29, 2009 at 4:07 PM, Nick Cox<n.j.cox@durham.ac.uk> wrote: >> Another common technique is just to count. >> >> if `: word count `0'' != 1 error 198 >> >> Note that Stata's definition of words includes explicitly quoted strings >> as single words. >> >> If a program took a string message and a number value as in >> >> program nathan >> version 11 >> args message answer >> di as txt "`message' " as res `answer' >> end >> >> nathan "the answer is" 42 >> >> -word count `0'- would still count the number of arguments to be 2. >> >> Nick >> n.j.cox@durham.ac.uk >> >> Nick Cox >> >> I often do something like this >> >> program example >> version 10.1 >> args factor garbage >> if "`factor'" == "" | "`garbage'" != "" { >> error 198 >> } >> >> You can approach this in other ways, but I find this to be among the >> most transparent. >> >> Nick >> n.j.cox@durham.ac.uk >> >> Nathan Danneman >> >> I have written a program, which utilizes the args command. The >> program analyzes regression results, and requires the user to input a >> single constant. Is there a way to generate an error message if the >> user inputs an incorrect number of arguments (either none, or more >> than one)? >> >> Here is what the program looks like... >> >> capture program drop example >> program example >> version 10.1 >> args factor >> ** I would like to input a line here that would do something like (if >> number of args != 1, then error "wrong number of arguments") >> ... >> ... >> >> end >> >> >> * >> * 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/ >> > > > > -- > "Imagination is more important than knowledge..." > -- Albert Einstein > -- "Imagination is more important than knowledge..." -- Albert Einstein * * 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/

**References**:**st: generate an error message if the wrong number of args is given following the args command***From:*Nathan Danneman <ndanneman@gmail.com>

**st: RE: generate an error message if the wrong number of args is given following the args command***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: RE: RE: generate an error message if the wrong number of args is given following the args command***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: How to Plot Panel Data Models or Fitted Curves** - Next by Date:
**RE: st: Analyzing a subpopulation in Stata 10.1** - Previous by thread:
**st: RE: RE: generate an error message if the wrong number of args is given following the args command** - Next by thread:
**st: RE: seemingly unrelated regression** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |