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

Re: st: RE: programs with options

From   Jean-Benoit Hardouin <>
Subject   Re: st: RE: programs with options
Date   Fri, 11 Jul 2003 17:42:31 +0200

This is perfect,
Thank you
Jean-Benoit Hardouin

On Fri, 11 Jul 2003 11:26:39 -0400, David Kantor <> wrote:

To Jean-Benoit Hardouin:

You are referring to `1', `2', `3', etc., which are just the non-blank textual segments of the command line (after the command name). Thus, the final one (`2' in your examples) may include the comma if there is no space after it in the command line.

These are not the same as the elements of the varlist -- until you - tokenize `varlist'-.

So one solution is to put
tokenize `varlist'
into your program, before the `forvalues-statement. But a better way to do this would be...

foreach var of local varlist {
di "`var'"

(And you won't need `nbitems'.)

I hope this helps.
-- David

At 05:06 PM 7/11/2003 +0200, you wrote:

See for example

program define testop

syntax varlist(min=2 numeric) [,option1 option2]
local nbitems : word count `varlist'

forvalues i=1/`nbitems' {
di "``i''"

.testop var1 var2 ,option1

.testop var1 var2, option1

.testop var1 var2,option1
David Kantor
Institute for Policy Studies
Johns Hopkins University

*   For searches and help try:

*   For searches and help try:

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