Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Optional arguments in Mata


From   "Le Wang" <[email protected]>
To   [email protected]
Subject   st: Optional arguments in Mata
Date   Mon, 1 Oct 2007 14:11:45 -0500

Hi there,

Thanks in advance for your time.

I am trying to program a Mata function with optional arguments. For
example,  I want to: (1) read the data y and x (2) create a matrix
equals x and J(rows(x),1,1) (constant) (3) create a matrix x'*y

void myfunction(string scalar depvar, | string scalar varlist)
{
      st_view(y=.,.,depvar,.)
      st_view(x=.,.,varlist,.)

      x=x,J(rows(x),1,1)

      x'*y
}

The program will work fine if i specify the varlist
        myfunction("y","x")

However, it won't work if I don't specify the varlist because
"st_view(x=.,.,varlist,.)" requires an argument. How should I solve
this problem?

Thanks.

Le
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Le Wang, Ph.D.
Minnesota Population Center
University of Minnesota
(o) 612-624-5818
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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