Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: syntax error
From
"David Rivenbark" <[email protected]>
To
<[email protected]>
Subject
RE: st: syntax error
Date
Tue, 22 Oct 2013 21:04:26 -0400
Nick and Sergiy:
Thank you for the responses. When I wrote f(), I was simply trying
to indicate that q is a function of the program arguments. My program now
runs and I can finish debugging.
David
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Tuesday, October 22, 2013 7:15 PM
To: [email protected]
Subject: Re: st: syntax error
-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.
Nick
[email protected]
On 23 October 2013 00:03, David Rivenbark <[email protected]> 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:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/