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

RE: st: Stata 6 vs. 7


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Stata 6 vs. 7
Date   Mon, 9 Sep 2002 15:26:32 +0100

HJW wrote

> >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.]

and Roger Newson replied 
> 
> 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 am not clear about several aspects of this problem. 
For example, what is meant exactly by running under 
version 6? There is a big difference between 

(a) running a Stata 7 executable and within that 
running a program with a -version 6.0- statement. 

(b) running a Stata 6 executable. 

The two are not equivalent. Under (a) Stata 7 
does _not_ forget all that it knows about Stata 
7.0 syntax changes. 

I suspect it is not that 

> Stata 6 probably expects variable names in -myopt-,
> so when no name is given it complains. 

Rather the problem is that Stata 6.0 (strong sense) 
just does not understand the syntax of your 
-syntax- statement. How could it? 

Roger's solution seems to suppose that you 
have a Stata 7 executable and want to run 
a program with -version- set to 6.0. I 
am not clear that that is your situation. 

One way to do what you want might be to let -myopt()- 
take a string within -syntax- and to do processing 
of any supplied string argument using -unab-. 
Other elements being understood, 

	version 6.0
	syntax , [myopt(str)]
	if "`myopt'" != "" { 
		unab myopt : `myopt'
	} 

Nick 
n.j.cox@durham.ac.uk 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index