Statalist


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

Re: st: Date calculation


From   "Ziad El-Khatib" <Ziad.El-Khatib@ki.se>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Date calculation
Date   Sat, 27 Oct 2007 13:56:22 -0700

Thank you!
when i type
gen ndate = date(date, "DMY")

it sayd type mismatch, i am using ver 9.2, is it something in the text
or version related?

Thank you and best regards
ziad



On 10/27/07, Maarten buis <maartenbuis@yahoo.co.uk> wrote:
> --- Ziad El-Khatib <Ziad.El-Khatib@ki.se> 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/
>


-- 
Ziad El-Khatib
AIDS Unit
National Institute for Communicable Diseases (NICD)
1 Modderfontein Road
Private Bag X4, Sandringham, 2131
Johannesburg, South Africa
Mobile: +27 (0) 72-52 39 716
Phone: +27 (0) 11-386 6433
Fax (NICD): +27 (0)11 386 6453
Fax (alternative): +27 (0)866 18 2871
http://www.nicd.ac.za/

Division of International Health (IHCAR)
Karolinska Institutet
www.phs.ki.se/ihcar
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index