Dawood Ashraf wrote
> I am trying to calculate degree of concentration in an industry
> by using the Herfindahl index. I am using the panel data where
> I have 10 years of time, 50 states, in every state there are a
> few companies.
> bysort state: generate HERF= (asset/ sum(asset))^2 if repdte==1997
The solutions presented by others are all you really need to generate your indices. However, if you are interested in a one-liner as an alternative, I wrote a routine a few years ago to compute Herfindalh-Hirschman indices. You can save the code below (beware of lines that may wrap or inadvertently cut off) as a file called _ghhi.ado somewhere on your ado path, and generate an index as
egen HERF = hhi(asset) if repdte==1997, i(state)
The documentation is included in the -egenmine.hlp- file, which is a subset of my own suite of egen routines to complement the excellent egen and egenmore packages.
Pat Joly
----_ghhi.ado------<copy from the next line...>-----
*! _ghhi: generate herfindahl index of industry concentration
*! version 1.1 16aug2002 PJoly
* v.1.0 20feb2002 PJoly
program define _ghhi
version 7
gettoken type 0 : 0
gettoken g 0 : 0
gettoken eqs 0 : 0
syntax varname [if] [in], i(varname) [ t(varname) ]
marksample touse, novarlist
tempvar totsls mktshsq
qui {
sort `touse' `t' `i'
by `touse' `t' `i': g double `totsls' = sum(`varlist') if `touse'
by `touse' `t' `i': replace `totsls' = `totsls'[_N]
by `touse' `t' `i': g `type' `g' = /*
*/ sum((100*`varlist'/`totsls')^2) if `touse'
by `touse' `t' `i': replace `g' = `g'[_N] if `touse'
* concenc and total sales surely not 0 in an entire industry
replace `g' = . if `g'==0
}
la var `g' "Herfindahl index, Group(`i')"
end
exit
----------<...to the line above>-----
----egenmine.help------<copy from the next line...>-----
{smcl}
{* 01dec2001}{...}
{hline}
help for {hi:egenmine}{right:[P.Joly]}
{hline}
{title:My own extensions to generate}
{p 8 27}
{cmd:egen}
[{it:type}] {it:newvar} {cmd:=}
{it:fcn}{cmd:(}{it:arguments}{cmd:)}
[{cmd:if} {it:exp}]
[{cmd:in} {it:range}]
[{cmd:,}
{it:options}
]
{p}
{cmd:by} {it:...} {cmd::} may be used with some {cmd:egen} functions
as noted below; see help {help by}.
{title:Description}
{p}
{cmd:egen} creates {it:newvar} of the optionally specified storage
type equal to {it:fcn}{cmd:(}{it:arguments}{cmd:)}.
Depending on {it:fcn()}, {it:arguments}, if present, refers to an
expression, {it:varlist}, or a {it:numlist} and the {it:options}
are similarly {it:fcn} dependent.
Note that the explicit subscripting (using {cmd:_N} and {cmd:_n}),
which is commonly used with {cmd:generate}, should not be used with
{cmd:egen}; see {hi:[U] 16.7 Explicit subscripting}.
{title:{cmd:Egen} functions}
{cmd:hhi(}{it:salesvar}{cmd:),} {cmd:i(}{it:idvar}{cmd:)} {...}
[{cmd:t(}{it:timevar}{cmd:)}]
{p 4 4}
may not be combined with {cmd:by} since option {cmd:i()} in effect
defines the group variable.
{cmd:hhi()} generates a Herfindahl index of industry concentration
based on {it:salesvar}, a variable representing the total sales of a
firm within an industry.
The values of any Herfindahl index lie between 0 and 10,000.
{it:idvar} specifies the industry variable and {it:timevar}, which is
optional, specifies the time variable.
{title:Author}
Patrick Joly, Industry Canada
{title:Also see}
{p 0 19}
On-line: help for
{help egen},
{help egenmore}
(if installed)
{p_end}
----------<...to the line above>-----
*
* 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/