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]

From |
Ly Tran <lyhuyen@brandeis.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Re-access a matrix in mata through a mata function |

Date |
Wed, 30 Jan 2013 11:30:04 -0500 |

So I have this large matrix (appx. 5000x5000) in Mata (the Stata version that I have does not allow a matrix of that size in Stata). To fill up this matrix, I have to run 5000 repetitions, each time adding the calculated values into one column of the matrix. This part is in an ado file that I wrote, so in order to update the matrix, I had to do this: forval i = 1/5000 { .... // calculating the new values, save it in variable X mata: R[i,.] = X' // this is just a gist of it, my actual code is a couple of lines longer } I would like to put those couple of lines "mata: R[i,.] = X'" into a mata function. But when I right a function, mata void updateR(real scalar i) { R[i,.] = X' } end, the matrix R does not exist within the function, so the error is always "Subscript invalid". Again, let's assume that in my actual program, I take care of the validity of i and X. I just wonder if there is anyway to solve this problem, i.e. accessing R through a mata function. The next part requires a lot of work with R, so I would really like to write a function/program for it, instead of doing "mata:" for the next hundred lines. Is there a way for me to stick with Stata instead of using Matlab to write this program? Thank you. But the next part is to -- Ly Tran * * 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/

**Follow-Ups**:**Re: st: Re-access a matrix in mata through a mata function***From:*Aljar Meesters <aljar.meesters@gmail.com>

- Prev by Date:
**st: Explanatories that vary only over time in panel data** - Next by Date:
**Re: st: Re-access a matrix in mata through a mata function** - Previous by thread:
**st: Explanatories that vary only over time in panel data** - Next by thread:
**Re: st: Re-access a matrix in mata through a mata function** - Index(es):