Statalist The Stata Listserver


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

Re: st: Getting the latest "previous date"


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Getting the latest "previous date"
Date   Tue, 12 Dec 2006 10:27:38 +0100

Gustaf wrote:

I have a set of observations, and for each observation I have one
event date and n visit dates. How would I go about to get the date for
the last visit that occured before my event?
I'm guessing to use something like egen lastvisitdate=
rmin(eventdate-visitdate*), bu a) I'm not allowed to do that, and b) I
don't know how to only return positive values.
-----------------------------------------------------------

This demonstrates a way to do it:

-----
// I created an artificial dataset, 20 observations,
// 1 eventdate and 6 visitdates
clear
set obs 20
gen id=_n
set seed 12345
gen edate = int(15000 + 1000*uniform())
forvalues X=1/6 {
   gen vdate`X' = int(15000 + 1000*uniform())
}

// Remove visitdates after eventdate
foreach V of varlist vdate1-vdate6 {
   replace `V' = . if `V' > edate
}

// the last visit before eventdate:
egen ldate = rmax(vdate1-vdate6)
format edate-ldate %d
-----

Hope this helps
Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________ 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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