Statalist The Stata Listserver


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

st: mata: how function can return several results


From   "U.A.QU.AP" <uaquap@gnet.tn>
To   statalist@hsphsun2.harvard.edu
Subject   st: mata: how function can return several results
Date   Sun, 15 Oct 2006 03:03:12 +0200 (CEST)

I would like to write a subroutine in mata that can return a several result a once. More precisely if I define a function (myreg for exemple ) defined as
-------------start myreg
function myreg () {

st_view(y, .,  st_local("yvar"))
st_view(x, ., st_local("xvar"))
bhat=invsym(x'*x)x'*y   // estimated coefficient
uhat=y-x*bhat       // residual 
}
----------- finish myreg
how can i tell mata to return 2 results
res1=bhat and res2=uhat. res1 and res2 are for use in the rest of my programme. 
Ideally I want some thing like this:
{b,u}=myreg() as can i code in gauss for exemple
Abdelrahmen El Lahga
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index