Dear All, I find this question here (https://bbs.pinggu.org/forum.php?mod...=1#pid57289524). The dataset is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long id float a int yearin float n
11000208  7 2008 2
11000208  8 2011 2
11000308  7 2008 3
11000308  9 2011 3
11000308  9 2014 3
11000808  6 2008 2
11000808 12 2011 2
11001008  7 2008 2
11001008 12 2011 2
11001108  6 2008 2
11001108  6 2011 2
11001208  8 2008 3
11001208  8 2011 3
11001208  9 2014 3
11001308 10 2008 2
11001308 11 2011 2
11001408  6 2008 2
11001408  6 2011 2
11001508  6 2008 2
11001508  6 2011 2
11001708  6 2008 2
11001708 11 2011 2
11001808  6 2008 2
11001808 11 2011 2
11002308  6 2008 3
11002308  6 2011 3
11002308  6 2014 3
11002508  8 2008 3
11002508  7 2011 3
11002508 14 2014 3
11002908  6 2008 3
11002908  6 2011 3
11002908  6 2014 3
11003008  6 2008 3
11003008  6 2011 3
11003008  6 2014 3
11003108  6 2008 3
11003108  6 2011 3
11003108  6 2014 3
11003708  6 2008 2
11003708  8 2011 2
11003808  6 2008 3
11003808  6 2011 3
11003808  6 2014 3
11003908  6 2008 3
11003908  6 2011 3
11003908 14 2014 3
11004308  6 2008 3
11004308  6 2011 3
11004308  8 2014 3
11004408  6 2008 2
11004408  6 2011 2
11004508  7 2008 2
11004508  9 2011 2
11004808  7 2008 2
11004808  6 2011 2
11005008  6 2008 2
11005008  6 2011 2
11005308  6 2008 2
11005308 16 2011 2
11005708  6 2008 2
11005708  6 2011 2
11006008  6 2008 3
11006008  6 2011 3
11006008  8 2014 3
11006108  6 2008 3
11006108  8 2011 3
11006108 14 2014 3
11006208  6 2008 2
11006208 16 2011 2
11006508  6 2008 3
11006508  6 2011 3
11006508 11 2014 3
11006608  6 2008 3
11006608  6 2011 3
11006608  6 2014 3
11006708  6 2008 3
11006708  6 2011 3
11006708  6 2014 3
11006908  6 2008 3
11006908  6 2011 3
11006908  6 2014 3
11007108  6 2008 3
11007108  6 2011 3
11007108 13 2014 3
11007408  6 2008 3
11007408  6 2011 3
11007408  6 2014 3
11007608  6 2008 2
11007608 12 2011 2
11007708  6 2008 3
11007708  6 2011 3
11007708  6 2014 3
11007808  6 2008 2
11007808  6 2011 2
11007908  6 2008 3
11007908  6 2011 3
11007908  6 2014 3
11009008  6 2008 2
11009008  6 2011 2
end
Suppose that we want to drop `id' with the following situations.
  1. For each `id' with `n=2', if the value of `a' in the latter year is smaller than its value in the previous year, drop this `id' (e.g., id=11004808).
  2. For each `id' with `n=3 or 4 (no observations here though)', if the value of `a' in the very last year is smaller than any of its values in the previous years, drop this `id' as well. (to keep `id' with maximum value in the last period).
Any suggestions are highly appreciated.