How about:
void myfunction(string scalar depvar, | string scalar varlist)
{
st_view(y=.,.,depvar,.)
if (args()<2) x = J(rows(y),0,.)
else st_view(x=.,.,varlist,.)
x=x,J(rows(x),1,1)
x'*y
}
ben
On 10/1/07, Le Wang <[email protected]> wrote:
> 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/
>
*
* 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/