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

st: FW: More Tab and Matrix


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: FW: More Tab and Matrix
Date   Thu, 13 Jun 2002 15:23:41 -0400

On further review, I note a problem with my suggestion here -- I use the
overall N in the denominator, not the manufacturer-specific N.  This
could be patched, but since the Other Nick has addressed this already, I
leave it as an exercise.

Cheers,
_Nick Winter

-----Original Message-----
From: Nick Winter 
Sent: Thursday, June 13, 2002 2:44 PM
To: '[email protected]'
Subject: RE: More Tab and Matrix


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

<<winmail.dat>>




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index