Robert wrote:
I have data like:
id bid time
1 1 1
1 3 3
1 4 2
1 8 4
1 10 5
1 12 6
1 14 8
1 17 7
2 5 1
2 6 2
2 9 3
And I want to calculate things like max, mean or rank:
*) by id
*) stepwise inside the id's
That means f.e if in line 3 of id x I want to create an value that
expresses max(bid[1] bid[2] bid[3]).
So generally speaking a stepwise func(bid[1] ...bid[n]) foreach
single n, by id.
------------------------------------------------------------
It is not quite clear what you want. Your data seem to be sorted by
id and bid rather than id and time. Should they be ranked according
to the level of bid within each id?
When data are sorted by id and bid, then max(bid[1] bid[2] bid[3])
must be bid[3].
The ranks and maximums can be calculated by:
clear
input id bid time
1 1 1
1 3 3
1 4 2
1 8 4
1 10 5
1 12 6
1 14 8
1 17 7
2 5 1
2 6 2
2 9 3
end
sort id bid
by id: gen rank=_n
by id: egen maxbid=max(bid)
list
+---------------------------------+
| id bid time rank maxbid |
|---------------------------------|
1. | 1 1 1 1 17 |
2. | 1 4 2 2 17 |
3. | 1 3 3 3 17 |
4. | 1 8 4 4 17 |
5. | 1 10 5 5 17 |
|---------------------------------|
6. | 1 12 6 6 17 |
7. | 1 17 7 7 17 |
8. | 1 14 8 8 17 |
9. | 2 5 1 1 9 |
10. | 2 6 2 2 9 |
|---------------------------------|
11. | 2 9 3 3 9 |
+---------------------------------+
Hope this helps
Svend
________________________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: [email protected]
_________________________________________________________
*
* 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/