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

st: RE: ineq & Herfendahl Index


From   "Paul Seed" <[email protected]>
To   <[email protected]>
Subject   st: RE: ineq & Herfendahl Index
Date   Fri, 14 Jun 2002 11:45:07 +0100

Steven Fraser's problem can also be approached using standard
Stata commands (although I was interested to see a demonstration of -ineq-)


> Date: Thu, 13 Jun 2002 09:48:59 -0400
> From: "Fraser, Steven" <[email protected]>
> Subject: st: Tab and Matcell
>
> Dear Statalist:
>
> I am having a problem implementing matrix operations within the 'tab'
> command.  Using a variation of the familiar car example, assume I have the
> following dataset:
>
> Manuf		Model		Class		MPG
> ford		explorer		SUV		12
> ford		expedition	SUV		10
> ford		focus		compact	34
> dodge		durango		SUV		16
> gm		tahoe		SUV		15
>
> Assume I have hundreds of automobiles (cars, trucks, and SUVs).
> I am trying
> to develop a focus measure (a Herfandahl index) that captures the focus of
> the manufacturer.

bysort manuf class : gen i_2 = _N if _n == 1
replace i_2 = i^2
bysort manuf  : gen n_2 = _N if _n == 1
replace n_2 = n^2
egen simpson = sum(i_2) , by(manuf)
replace simpson = simpson/n_2
li manuf simpson if simpson ~= .
by manuf : replace simpson = simpson[1]

This longer approach has the (small) advantage over -ineq-
that the index is added to the existing data base, not to the collapsed
version, so can be compared at once with any other variables of interest.


************************
Paul Seed
[email protected]
Medical Statistician
Wolfson Institute of Preventive Medicine
Charterhouse Square
London EC1M  6BQ
(020) (+44) 7882 6298
fax 7882 6270

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