Statalist


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

RE: st: re: syntax


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: re: syntax
Date   Sun, 19 Oct 2008 16:45:45 +0100

Not so. -syntax- isn't dumb, or confused, at all. It doesn't set local
macros 1, 2, etc. so you are placing blame in the wrong place. See my
earlier posting. 

Nick 
[email protected] 

David Airey

Right, but I wanted

syntax varname1 varname2 [if] [in] [, noconstant]

so I typed

syntax varlist(min=2 max=2 numeric) [if] [in] [, noconstant]
tokenize `varlist'
local varname1 `1'
local varname2 `2'

I was just curious why -syntax' isn't smart enough not to be confused  
about the option commas not being separating by white space. The code  
below is not smart enough.

syntax varlist(min=2 max=2 numeric) [if] [in] [, noconstant]
// tokenize `varlist'
local varname1 `1'
local varname2 `2'

Incidentally, this is related to exercises in one of the Stata  
courses. Since I got this to work, and Stata instructors don't work  
weekends, I'm posting here. So I hope this is not classified as  
posting homework! :)

-Dave

On Oct 19, 2008, at 10:24 AM, Kit Baum wrote:

> < >
> Dave said
>
> I have not used syntax much. When I write the syntax command,
>
> syntax varlist(min=2 max=2 numeric) [if] [in] [, noconstant]
>
> I find it parses
>
> mycommand weight weight2 , constant
>
> differently than
>
> mycommand weight weight2, constant
>
> The top parses `2' to weight2 and the bottom parses `2' to weight2,
> (includes the comma). Use of tokenize varlist avoids this problem, but
> is it a long standing feature of syntax to require option commas to be
> separated by white space? I can't remember being careful about how I
> type that interactively.
>
>
>
>
> Rather than using numbered macros with -syntax-, just use the  
> returned -varlist-:
>
> program dave
> syntax varlist(min=2 max=2 numeric) [if] [in] [, noCONStant]
> di " varlist is `varlist'"
> di " constant is `constant'"
> end
>
> sysuse auto,clear
> dave price mpg , cons
> dave price mpg,nocons
> dave price mpg , nocons

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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