Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: syntax error

From   Nick Cox <>
To   "" <>
Subject   Re: st: syntax error
Date   Wed, 23 Oct 2013 00:14:52 +0100

-gettoken- does not work the way you want. It takes the first token
and optionally (re)names what is left when that is done. But it's not
what you seem to want anyway. It seems that you want to start your
program something like this, as I infer that you always want to
specify 3 variables.

syntax varlist(min=3 max=3)
tokenize `varlist'
args y x1 x2
tempvar q

However, your next line will not work

 gen double `q' = f(`y',`x1',`x2')

as no Stata function has the name -f()-. Perhaps you mean -F()-, perhaps not.

On the other hand, if you want to allow any of -y-, -x1-, -x2- to be
numeric constants, this syntax won't work.

As your program did nothing to support -if- and -in- allowing them as
legal syntax is, so far, a bug.

In short, some solutions can be suggested but other solutions depend
on knowing what you want to calculate.


On 23 October 2013 00:03, David Rivenbark <> wrote:
>             I have written a simple rclass program that has the following
> structure.
> Program MYprog, rclass
>      syntax varlist [if] [in] [, opt1(real 0) opt2(real 0) . ]
>      gettoken y x1 x2 : varlist
>      tempvar q
>      gen double `q' = f(`y',`x1',`x2')
>      sum `q'
>      return scalar mean=r(mean)
> end
> When I run the program with "MYprog y x1 x2" I receive an "invalid syntax"
> error message Stata reaches -gettoken-. Can someone help me understand my
> error using -gettoken-?
> *
> *   For searches and help try:
> *
> *
> *
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index