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: Problems with mata:st_view and syntax

From   Nick Cox <>
To   "" <>
Subject   Re: st: Problems with mata:st_view and syntax
Date   Sun, 21 Jul 2013 10:03:52 +0100

Correct spelling is Stata, as a careful reading of the FAQ would show.
Also, in Stata "function" is not a synonym for program or command; it
has its own separate meaning.

I will take the second problem.

The error here lies in supposing that -args- bears any relation to
-syntax-. It is totally independent of -syntax-.

When you type in a command line, in this case

foo a, opt(b)

Stata parses what you type after the command name (here -foo-) into
tokens, and the rules are merely that spaces divide but " " and `" "'
unite. Thus your tokens are

1     a,
2    opt(b)

and these tokens are placed by Stata in local macros 1 and 2. The
effect of your -args- statement is to map the contents of local macro
1 to arg (and to ignore any other macros) with the result you showed.

What you want is to add this line after the -syntax- statement:

tokenize `namelist'

which overrides Stata's initial parsing and places the tokens of
`namelist' in local macros named 1 up.


On 21 July 2013 04:33, Yosua Michael Maranatha <> wrote:
> Dear Stata list,
> I am new to STATA programming and just recently  I got two unexpected behaviours.
> The first one is about mata:st_view. Consider the following STATA code:
> --------------------------------------------------------------------------
> clear
> clear mata
> set obs 5
> gen a=1
> gen b=2
> gen c=3
> mata: st_view(X=., ., "a c")
> mata: X   /* ---> Correctly shows column a and c */
> drop b
> mata: X   /* ---> Showing column a and empty column! */
> ---------------------------------------------------------------------------
> I expect the sub_view X wouldn’t change (still a and c) after I dropped column b.
> However, somehow dropping b would affect the sub_view X.
> Is there a way to avoid this behaviour?
> My second problem is regarding syntax. Consider the following STATA function:
> ------------------------------------------------------------------------
> capture program drop foo
> program define foo
>                 syntax namelist, opt(name)
>                 args arg
>                 display "`arg'"
> end
> ------------------------------------------------------------------------
> When I call the function with command:
> $ foo a, opt(b)
> it would display:
> $ a,
> The comma is really unexpected. I expect the argument arg to be only “a” instead of “a,”.
> I can avoid this problem by use the following function call:
> $ foo a ,opt(b)
> , however this is not really convenient for the user (supposing I am making an ado files).
> Is there a good way to avoid this problem?

*   For searches and help try:

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