Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Stata 6 vs. 7


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: Stata 6 vs. 7
Date   Sun, 08 Sep 2002 18:38:00 +0100

At 15:22 07/09/02 -0700, HJW wrote:
Hi,

It seems I encountered an inconsistency between Stata 6 and
7, and I would like to ask for help. Say I have a program
like the follows.

   program define myexpl
     version 6.0
     syntax ...., ..... [myopt(varlist) .... ]

   end

In Stata 7, if I issue the command,

  myexpl ....., myopt()   /* empty in -myopt- */

then Stata will return empty for `myopt' in the program,
which is what I want.  However, if the same program runs
under Stata 6, then Stata complains with the message:

   myopt() is invalid

I know Stata 6 probably expects variable names in -myopt-,
so when no name is given it complains. However, I need the
behavior of Stata 7; is there any way to let Stata 6 behaves
like its next generation does? Something like default=none
may do, but this does not seem to work on options. Can
anyone help?  Thanks in advance.

[Just for those curious: I know his situation is odd,
because if an empty string is desired, why specify the
option -myopt- in the first place? Well, this is a part of a
complicated maximum likelihood program, which estimates
several different models. In order to preserve syntax
consistency across models, -myopt- is required if a
particular model is called, no matter whether it eventually
contains a varlist or an empty string. Alright, this may be
my own eccentric programing style, but please spare me with
the eccentricity.]
In the calling program, you can define a local macro equal to -myopt(varlist)- if the varlist is non-empty, and equal to an empty string otherwise. For instance, if the varlist is in a macro -vlist-, then you might have some lines, in your calling program, as follows:

local myoptv ""
if "`vlist'"!="" {
local myoptv "myopt(`vlist')"
}
myexpl,`myoptv'

and -myexpl- will be called with the -myopt- option if, and only if, the macro -vlist- is non-empty.

I hope this helps.

Roger



--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]

Opinions expressed are those of the author, not the institution.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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