| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re:Combining forvalues and by
Pierre a dit:
I am trying to calculate the so-called h index for a large number of
scientists. The h index of a scientist and the highest integer h such
that the scientist has h papers cited at least h times.
As is often the case, no explicit looping over observations is
necessary nor desirable.
. list,sepby(var1)
+--------------------------+
| var1 var2 var3 |
|--------------------------|
1. | GEORGE 10101157 8 |
2. | GEORGE 12242494 10 |
3. | GEORGE 11156976 12 |
4. | GEORGE 9409826 19 |
5. | GEORGE 7635312 23 |
6. | GEORGE 7799970 23 |
7. | GEORGE 11290701 28 |
8. | GEORGE 8034742 42 |
9. | GEORGE 8334302 43 |
10. | GEORGE 2656402 74 |
11. | GEORGE 2005819 79 |
12. | GEORGE 2643162 111 |
13. | GEORGE 8943317 127 |
14. | GEORGE 1956405 146 |
15. | GEORGE 9314530 153 |
16. | GEORGE 2404021 204 |
17. | GEORGE 3049620 302 |
18. | GEORGE 2195038 373 |
19. | GEORGE 2476649 393 |
20. | GEORGE 2005809 527 |
21. | GEORGE 6365931 614 |
22. | GEORGE 6365930 670 |
|--------------------------|
23. | HENRY 10101157 18 |
24. | HENRY 12242494 20 |
25. | HENRY 11156976 22 |
26. | HENRY 9409826 29 |
27. | HENRY 7635312 33 |
28. | HENRY 7799970 33 |
29. | HENRY 11290701 38 |
30. | HENRY 8034742 52 |
31. | HENRY 8334302 53 |
32. | HENRY 2656402 84 |
33. | HENRY 2005819 89 |
34. | HENRY 2643162 121 |
35. | HENRY 8943317 137 |
36. | HENRY 1956405 156 |
37. | HENRY 9314530 163 |
38. | HENRY 2404021 214 |
39. | HENRY 3049620 312 |
40. | HENRY 2195038 383 |
41. | HENRY 2476649 403 |
42. | HENRY 2005809 537 |
43. | HENRY 6365931 624 |
44. | HENRY 6365930 680 |
+--------------------------+
. gsort var1 -var3
. by var1: g beat=_n*(var3>=_n)
. by var1: egen h = max(beat)
. by var1: keep if _n==1
(42 observations deleted)
. list var1 h
+-------------+
| var1 h |
|-------------|
1. | GEORGE 19 |
2. | HENRY 20 |
+-------------+
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
*
* 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/