Statalist


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

Re: st: Date calculation


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Date calculation
Date   Sat, 27 Oct 2007 19:58:40 +0100 (BST)

--- Ziad El-Khatib <[email protected]> wrote:
> we observed patients at different time points and it is numbered
> under 'visit' variable as 1,2,3,4,5
> 
> And we know the date of each visit (variable named 'date')
> 
> I am trying to calculate the number of days between visits for each
> patient. Patients can be identified after their studyid.
> 
> For example, my aim is to have something as below
> 
> studyid           visit        date                             days
> 1001                1           01-01-2000                    0
> 1001                 2          15-01-2000                    14
> 1001                3            20-01-2000                   5
> 
> etc..

turn the date variable into a Stata date variable and than you can
within each studyid subtract the current date from the previous date,
see -help date-, -help by- and the example below:

*-------------------- begin example -------------------
clear
input long studyid visit  str10  date  
1001                1           01-01-2000
1001                2           15-01-2000
1001                3           20-01-2000
end

gen ndate = date(date, "DMY")
format ndate %td

bys studyid (ndate) : gen days = cond(_n == 1,           ///
                                      0,                 ///
                                      ndate - ndate[_n-1])
*-------------------- end example ----------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
*
*   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