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