[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Kit Baum <baum@bc.edu> |

To |
"Susan Olivia" <susan.olivia@gmail.com> |

Subject |
Re: st: re: matrix manipulation |

Date |
Fri, 12 Dec 2008 10:35:36 -0500 |

<>

--------------------- mata: mata clear mata: void underbar(string scalar mat, real scalar thresh) { real matrix B real scalar i B = (st_matrix(mat) :< thresh) :/ st_matrix(mat) for(i=1; i<=rows(B); i++) { B[i,i] = 0 } st_matrix("B", B) } end sysuse auto,clear qui reg price trunk weight length turn mat list e(V) mata: underbar("e(V)", 10) mat list B ------------------------

Kit Baum, Boston College Economics and DIW Berlin http://ideas.repec.org/e/pba1.html An Introduction to Modern Econometrics Using Stata: http://www.stata-press.com/books/imeus.html On Dec 12, 2008, at 09:50 , Susan Olivia wrote:

Thanks for the tips, Kit. I would like to use this opportunity toask 3 follow up questions:1) For each cell (i,j) of matrix B, I would like to replace itsvalue with 1/(A[ij]) instead of dummy [0 1] as in before. In otherwords, matrix B[i,j] = 1/A[i,j] if A[i,j] < THRESHOLD. I seem havingproblem in doing this.2) The syntax you suggested "underbar", I seem couldn't find thisentry in the STATA manual. Can you please explain what is thisdoing? Perhaps once I know what "underbar" is really doing, I cantackle #1.3) Also, when the threshold condition met, the diagonal element ofmatrix B is replaced to 1 or 1/aij. Ideally, I want the diagonalelement to be zero. Is there an efficient way to do this? What Icurrently do is transform the matrix into variables and use the loopto change the diagonal element and then transform the variables intothe matrix. I.e.svmat B local i=1 while `i'<=_N { qui recode B`i' 1=0 in `i' local i=`i'+1 } mkmat B*, matrix(B) Thanks in advance for any programming tips. Cheers, Susan On Thu, Dec 11, 2008 at 8:00 AM, Kit Baum <baum@bc.edu> wrote: <> Susan said I would like to create a binary matrix (say matrix B) using the existing information from current matrix A. Specifically, for each cell (i,j) of matrix B, I want to replace its value with 1 if the value of the corresponding cell (i,j) of matrix A is less than the specified threshold value. In other words, matrix B[i,j] = 1 if A[i,j] < THRESHOLD. No subscripting required: -------------------------------- mata: mata clear mata: void underbar(string scalar mat, real scalar thresh) { st_matrix("B", (st_matrix(mat) :< thresh)) } end sysuse auto,clear qui reg price trunk weight length turn mat list e(V) mata: underbar("e(V)",0.0001) mat list B -----------------------------------You could pass the name of the result matrix to Mata as well if youwanted this to be a bit more general.Kit Baum, Boston College Economics and DIW Berlin http://ideas.repec.org/e/pba1.html An Introduction to Modern Econometrics Using Stata: http://www.stata-press.com/books/imeus.html * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: re: matrix manipulation***From:*"Austin Nichols" <austinnichols@gmail.com>

**References**:**st: re: matrix manipulation***From:*Kit Baum <baum@bc.edu>

- Prev by Date:
**Re: st: rcal, measurement error model question** - Next by Date:
**Re: st: re: matrix manipulation** - Previous by thread:
**st: re: matrix manipulation** - Next by thread:
**Re: st: re: matrix manipulation** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |