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