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/