Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: multiple observations


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: multiple observations
Date   Wed, 10 Sep 2008 18:26:05 +0100

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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index