Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: deleting duplicate observations by date


From   Phil Schumm <[email protected]>
To   [email protected]
Subject   Re: st: deleting duplicate observations by date
Date   Tue, 13 Jan 2009 07:03:22 -0600

On Jan 13, 2009, at 6:28 AM, Sharooon wrote:
I have a data set with the following format:

id      date     price
1       1         400
2       1         500
2       2         450
2       3         450
3       2         600
3       3          .

Where I have multiple id's observed at different dates, and not necessarily the same date. What I would like, is to delete all but the most recent date and fill in the price with the most recent price observed.


bys id (date): replace price = price[_n-1] if mi(price)
bys id (date): keep if _n==_N


-- Phil

P.S. You could, if you want, follow this with

keep if !mi(price)

if you didn't want a record for those ids where there never was a non- missing value of price.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index