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: Using -return matrix- to return other rclass matrix results


From   "Lacy,Michael" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: Using -return matrix- to return other rclass matrix results
Date   Fri, 22 Feb 2013 17:49:01 +0000

Greetings,

I commonly want to return matrices in the midst of rclass programs, where such matrices come from
matrix results returned by other rclass programs.   What I usually do is clumsy, as it involves 
-tempname- and various reassignments. Here's a toy illustration:

cap prog drop sub
prog sub, rclass
  matrix U = (runiform(), runiform())
  return matrix A = U
  return scalar extra = runiform()
end
//
cap prog drop main
prog main, rclass
  tempname temp1 temp2
  sub 
  mat `temp1' = r(A) 
  sub 
  mat `temp2'  = r(A) 
  // do lots of other stuff, including 
  // e.g. CallSomeOtherProgram, matrix1(`temp1') matrix2(`temp2')
  //  do more stuff, and then at the end of main, return these and other results
  return matrix A1 = `temp1'
  return matrix A2 = `temp2'
  //return ... whatever ....
end
//
main
ret list

-----------------

If it were possible , I would do something in "main" like:
tab ..
return matrix A1 = r(A)
tab ...
return matrix A2 = r(A)
CallSomeOtherProgram ..., 

which of course won't work, since -return matrix-, as I understand it,  doesn't allow 
the direct assignment of matrices from r().  

The following works and saves a bit of memory, but is equally prolix:
tempname temp1 temp2
sub 
mat rename r(A) `temp1'
sub
mat rename r(A) `temp2'
...etc. 
return ... = `temp1' 
return  etc.

Using -return add- is possiblem as in:
sub
return add 
sub ...
return add

But this this would return any and all r(extra) material, which could be quiet a bit of 
extraneous junk. 

So, I'd 1) like to return matrices from r() as they are created without going
through the -tempname- and -mat rename- or assignment steps. and 2) to be able 
to pass these matrices to another program before returning them.  It seems
that creating temp matrices for this purpose is clumsy. Is there another approach?
I would presume so, but ...

Thanks,

Mike Lacy
Dept. of Sociology
Colorado State University
Fort Collins CO 80523





Mike Lacy
Assoc. Prof./Dir. Grad. Studies
Dept. of Sociology
Colorado State University
Fort Collins CO 80523-1784
970.491.6721 (voice)



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