| ![]() |
From | "Michael Blasnik" <michael.blasnik@verizon.net> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | st: Re: manipulating matrix elements |
Date | Tue, 28 Mar 2006 16:23:46 -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
* * 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–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |