Bookmark and Share

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]

st: Problems with mata:st_view and syntax


From   Yosua Michael Maranatha <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Problems with mata:st_view and syntax
Date   Sun, 21 Jul 2013 11:33:56 +0800

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?

Thanks!

*
*   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/


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