Hello, I have a panel data and I want to keep the observation with the minimum value of Days for each InstitutionID and Accper. Then, I want to get the Median of ForecastAccuracy for each Stkcd and Accper for the observations that I keep. In other words, for any certain Stkcd and Accper, if there is more than one observation for InstitutionID, then keep the one with the lowest value of Days. After that, compute the Median of ForecastAccuracy for each Stkcd and Accper.


Stkcd Accper Rptdt Days InstitutionID ForecastAccuracy
000001 2013-12-31 2013-10-23 69 10101837 0.0054
000001 2013-12-31 2013-12-16 15 10101837 0.0108
000001 2013-12-31 2013-10-22 70 101434 0.0108
000001 2013-12-31 2013-12-15 16 101434 0.1237
000001 2013-12-31 2013-12-16 15 101506 0.9677
000001 2013-12-31 2013-10-23 69 102333 0.0108
000001 2013-12-31 2013-10-23 69 104094 0.5699
000001 2013-12-31 2013-10-23 69 104096 0.1667
000001 2013-12-31 2013-10-22 70 104102 0.0323
000001 2013-12-31 2013-11-21 40 104102 0
000001 2013-12-31 2013-10-23 69 104104 0.129
000001 2013-12-31 2013-10-23 69 10416 0.0108
000001 2013-12-31 2013-10-23 69 104169 0.1774
000001 2013-12-31 2013-10-23 69 104393 0.1129
000001 2013-12-31 2013-10-22 70 105045 0.1237
000001 2013-12-31 2013-12-31 0 105045 0.1344
000001 2013-12-31 2013-10-22 70 105523 0.0323
000001 2013-12-31 2013-10-23 69 106033 0.0376
000001 2013-12-31 2013-10-22 70 106035 0.2527
000001 2013-12-31 2013-10-23 69 106064 0.129
000001 2013-12-31 2013-10-24 68 106064 0.129
000001 2013-12-31 2013-10-22 70 106067 0.0591
000001 2013-12-31 2013-11-15 46 106067 0
000001 2013-12-31 2013-10-23 69 106068 0.0215
000001 2013-12-31 2013-10-23 69 106071 0
000001 2013-12-31 2013-10-23 69 107973 0.1183
000001 2013-12-31 2013-10-22 70 10974 0.129
000001 2013-12-31 2013-12-15 16 10974 0.129