Hello, I have a data similar to the one below, but without the max3_value column. This is the one I would like to find, but I do not know how. max3_value takes the last 3 values of the value column (within a group of person) and finds the maximum value of them. Of course, if it is the first or the second observation, it outputs a missing value. For example: max3_value=10 in period 3 for person A is calculated as a max(10,5,3). I thought of transposing the data with lagged values, but still I do not know how calculate it within groups of person. I would kindly appreciate any help. person period value max3_value A 1 10 . A 2 5 . A 3 3 10 A 4 5 5 A 5 2 5 A 6 3 5 A 7 4 4 A 8 14 14 B 1 6 . B 2 5 . B 3 1 6 B 4 1 4 B 5 4 4

... View more