On 12/12/06, Svend Juul <[email protected]> wrote:
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
Thank you Svend!
I didn't think of actually altering the vdate variables. Much appreciated!
Now, to continue from your example:
The numbers in vdate are marking the collection round. Now I would
like to extract the round number of the "ldate", in order to use the
information collected from that round. I'm at a loss on how to do
this, i.e return the varname of the variable in a varlist that matches
a condition.
Sorry for taking up everyone's time,
Gustaf
--
email:[email protected]
tel: +46(0)703051451
address: Kantorsgatan 50:190 75424 Uppsala Sweden
*
* 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/