Statalist The Stata Listserver


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

st: manipulating matrix elements


From   Steve Vaisey <[email protected]>
To   [email protected]
Subject   st: manipulating matrix elements
Date   Tue, 28 Mar 2006 15:49:17 -0500

Hello all,

I am trying to implement the following formula for estimating the (standardized) informational entropy of a RxC contingency table: sum(p*ln(p))+ln(M) where p (subscript ij omitted) is the proportion of cases in each cell and M is the total number of cells. So far, I've only managed to accomplish the following:

tab var1 var2, matcell(Cell)
matrix Proportions = Cell/r(N)

Frankly, I'm amazed I've managed even this much, but now I'm stuck. What I need to do (as I understand it) is take the natural log of each element of the Proportions matrix, multiply it times its corresponding proportion, sum up all the elements, and add ln(M).

For some (probably good) reason, while you can easily multiply matrix elements by a scalar, you can't do something like:

matrix LnP = ln(Proportions)

I've tried this, but it gives a type mismatch error. Again, I'm sure this is for a good reason, but I'm not sure what to do.

So any idea what I should do?

Thanks,

Steve

--
====================================================
Stephen Vaisey
National Science Foundation Graduate Research Fellow
Caroline H. and Thomas S. Royster, Jr. Fellow
Department of Sociology
University of North Carolina at Chapel Hill
200 Hamilton Hall (CB #3210)
Chapel Hill, NC 27599

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index