Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: loops for regions

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: loops for regions Date Wed, 5 Sep 2012 20:55:31 +0100

```The first line confuses the -if- command and the -if- qualifier.

I didn't look in detail at later code, as there should be no need to
write your own code, as many programs exist. -search inequality- for a

In fact, in many ways this is a calculator problem easily tackled with Mata.

. mata
: freq = (0, 0, 3, 9, 9)
: pr = freq :/ sum(freq)
: sum(pr:^2)
.387755102

In fact, zero frequencies map to zero squared proportions and can be omitted.

This index, although often attributed to Herfindahl by economists who
know only their only literature, was in essence invented decades
before by Gini. I don't have the reference in my head, but I think it
is in Bishop, Y., Fienberg, S.E. and Holland, P.W. 1975. Discrete
multivariate analysis. Cambridge, MA: MIT Press. Please trump me by
providing a yet earlier reference.

Nick

On Wed, Sep 5, 2012 at 5:15 PM, Chiara Mussida <cmussida@gmail.com> wrote:

> I want to generate a variable herf1 which takes the value of the below
> index for region 1, and thereafter repeat this loop for all the region
> in my dataset. The problem is that with the below command I get the
> herf1 index for region 1, which is identycal in value (I tried) to the
> herf2 for region2 whether I repeat this llop for region2, by starting
> with "if reg==2, and so forward for all the regions.
>
> if reg==1 {
> tab cat12_2, gen(categ)
> forvalues k = 1 2 to 12 {
> sum categ`k', meanonly
>         gen share`k'=r(mean) if reg==1 /*shares of each occ cat on the total
> occupation, time t*/
> }
> }
>
> gen herf1=(share1)^2 + (share2)^2 + (share3)^2 + (share4)^2 +
> (share5)^2 + (share6)^2 + (share7)^2 + (share8)^2 ///
> + (share9)^2 + (share10)^2 + (share11)^2 + (share12)^2  /*Herfindhal
> Index Region1*/
> the variable reg takes 1 for region1, 2 for region2...up to 20 for
> region20. In other words, Stata does not compute the specific index
> for each region, but the same index region by region.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```