Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: More Tab and Matrix


From   "Nick Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: More Tab and Matrix
Date   Thu, 13 Jun 2002 14:44:07 -0400

> > /*  This sequence calculates the focus variables */
> > tab class, matcell(classmat)
> > mat nummat=catmat'*catmat
> > gen numerator=nummat[1,1]
> > gen denominator=(_N)^2
> > gen focus=numerator/denominator
> > list focus

Leaving aside what this beast might be called (and whether it is the
same as anything calculated by -ineq- or anything else, I'll point out
that you can do what you want for all manufacturers by tabulating class
against maker and just considering the diagonal of the resulting
cross-product matrix:

	tab class maker, matcell(classmat) matcol(colmat)
	mat focmat = (classmat' * classmat) / `r(N)'^2
	mat focmat = vecdiag(focmat)
	mat list focmat

Then to put it into a variable:

	gen focus=.
	local nc=colsof(focmat)
	forval i=1/`nc' {
		replace focus = focmat[1,`i'] if maker==colmat[1,`i']
	}
	mat drop focmat
	matdrop classmat

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