Statalist The Stata Listserver


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

RE: st: Getting the latest "previous date"


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Getting the latest "previous date"
Date   Tue, 12 Dec 2006 14:58:09 -0000

Other advice is that you won't get in Stata with 
this data structure. Consider a -reshape long-. 

Nick 
[email protected] 

Svend Juul
 
> 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
> -----

*
*   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