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

RE: st: multiple observations

From   "Nick Cox" <[email protected]>
To   <[email protected]>
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 


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:

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