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.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: median of consecutive groups - avoiding loops
I do not know if the following is possible, I hope anyone has an idea how to address
I would like to create a variable that gives me the median of two consecutive groups
for every group. Here is an example:
id group value median
1 1 5 ?
2 1 7 ?
3 1 8 ?
4 2 3 ??
5 2 5 ??
6 3 5 ???
7 3 7 ???
8 3 4 ???
9 3 2 ???
10 3 8 ???
The first ? should be the median of id 1-5, the ?? the median of id 4-10 and the ???
the one of id 6-10.
Does anyone know a command that would do this without needing to write a loop?
Really looking forward to any recommendations!