# st: element wise division of matrices

 From "Victor, Jennifer Nicoll" To "'statalist@hsphsun2.harvard.edu'" Subject st: element wise division of matrices Date Wed, 30 Jul 2008 15:53:10 -0400

```Hello list:

Thanks to Nick for recommending a running sum of matrices for my problem yesterday.  I worked like a dream. Now I have a new problem.

I have created two matrices in Stata using the matrix commands.  One is called "rawsum," a 438x1010 matrix.  The other is "bothvoting," also a 438x1010 matrix.

I need to create matrix agreecount=(rawsum+bothvoting)/2. No problem.

Now I need to create matrix agreerate=agreecount/bothvoting, where each i,j of 'agreecount' is divided by each i,j of 'bothvoting'.  I cannot find a command in Stata's matrix commands to do this type of element-wise division.

So, I've moved into Mata.  Mata has a simple element-wise division command: X=A:/B.

But, I am a novice Mata-user and I cannot figure out how to get my 438x438 matrix into Mata.  So, I've converted it back to a dataset using the 'svmat' command and I'm trying to get the data into Mata using the 'st_view' command.  My data has 438 observations and 438 variables.  Essentially, I want to use the command:
st_view(x., ., "agreecount1",..."agreecount438")

...then do the same with the 'bothvoting' data, then execute the e-w division command.

I've tried using the 'for' command but cannot figure out the successful execution of a loop in Mata because the syntax is different than Stata's.

How can I do this?  Or can you provide a more elegant solution?

Thank you.
___________________________________________
Jennifer Nicoll Victor
Assistant Professor
Department of Political Science
University of Pittsburgh
4600 Wesley W. Posvar Hall
(412) 624-7204
E-mail:  jnvictor@pitt.edu
Homepage:  http://www.pitt.edu/~jnvictor

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