[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Jean-Benoit Hardouin <jean-benoit.hardouin@club-internet.fr> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: programs with options |

Date |
Fri, 11 Jul 2003 17:06:13 +0200 |

See for example

program define testop

syntax varlist(min=2 numeric) [,option1 option2]

local nbitems : word count `varlist'

forvalues i=1/`nbitems' {

di "``i''"

}

end

.testop var1 var2 ,option1

var1

var2

.testop var1 var2, option1

var1

var2,

.testop var1 var2,option1

var1

var2,option1

How can I use the name of the second variable in my program without the comma if this one is not separated by a blank of the last variable ?

Jean-benoit Hardouin

On Fri, 11 Jul 2003 15:21:38 +0100, Nick Cox <n.j.cox@durham.ac.uk> wrote:

Jean-Benoit HardouinWhen I write a program with options, I must put a space between the last variable and the comma, else Stata don't understand that the last variable is "varK" and not "varK,". How resolve this problem.I think you must show us _exactly_ what your real program is. My guess is that you have a problem, but it is not this.

I have try to write my syntax line as :

syntax varlist[,option1 option2] instead of

syntax varlist [,option1 option2] but I obtain the same result.

Example with an xxx program :

xxx var1 var2 var3, option1 option2

=>, invalid name

=>r(198);

xxx var1 var2 var3 , option1 option2

=>OK

If I write a program

program p1 version 8 syntax varlist[,foo bar] di "is OK" end

then things work OK with

.. p1 mpg weight

.. p1 mpg weight,foo

.. p1 mpg weight, foo

.. p1 mpg weight , foo

.. p1 mpg weight ,foo

-- so in terms of both (a) how the program is written (b) what you fire at it, Stata is not fussed.

In practice, I would write something more like

program p1 version 8 syntax varlist [, foo bar] di "is OK" end

but that's personal style reference (and also -- and this is of some importance -- closer to Stata Corp's house style and the style of most Stata programmers).

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/

* * 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/

**Follow-Ups**:**RE: st: RE: programs with options***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: programs with options***From:*David Kantor <dkantor@jhu.edu>

**References**:**st: RE: programs with options***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: bootstrapping survey data** - Next by Date:
**Re: st: RE: programs with options** - Previous by thread:
**st: RE: programs with options** - Next by thread:
**Re: st: RE: programs with options** - Index(es):

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