I doubt that you can identify the last observation for each -id- in any
sense unless you already have some variable indicating time.
It is that variable you should sort on within -id-.
Given that, there should be a one-line solution akin to
bysort id (time) : gen byte last = _n == _N
Nick
Ronan Conroy
Replying on how to tag the last observation for each case,
On 8 Sep 2008, at 13:14, fjc fjc wrote:
> You can also try:
>
> gen newid = .
> bysort id: replace newid = 1 if _n == _N
The problem is to make sure that the last observation for each id is
really the last observation.
To be doubly sure, you need a variable that identifies the
observation, then make sure that it too is sorted
bysort id (obsnumber) : replace newid=1 if _n == _N
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/