Statalist The Stata Listserver


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

Re: st: manipulating matrix elements


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: manipulating matrix elements
Date   Tue, 28 Mar 2006 22:25:43 +0100 (BST)

Steve:
A not very fancy sollution is to loop over the rows and the columns, like the example code below.
HTH,
Maarten 

*---------------begin example-----------
sysuse auto, clear
recode rep78 1=3 2=3
tab rep78 foreign, matcell(Cell)
matrix Proportions = Cell/r(N)
local r = rowsof(Proportions)
local c = colsof(Proportions)
local p = 0
forvalues i = 1/`r' {
	forvalues j = 1/`c' {
		local p = `p' + Proportions[`i',`j']*ln(Proportions[`i',`j'])
	}
}
local p = `p' + ln(`r'*`c')
di `p'
*-----------end example----------------

--- Steve Vaisey <[email protected]> wrote:

> 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)


-----------------------------------------
between 1/2/2006 and 31/3/2006 I will be
visiting the UCLA, during this time the
best way to reach me is by email

Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


		
___________________________________________________________ 
Yahoo! Photos � NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com
*
*   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