Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: dates and elapsed time


From   "Michael N. Mitchell" <Michael.Norman.Mitchell@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: dates and elapsed time
Date   Mon, 09 Aug 2010 18:51:54 -0700

In addition to Kieran's helpful answer, I would also recommend

http://www.ats.ucla.edu/stat/stata/modules/dates.htm

which contains a quick rundown of dates in Stata.

I hope that helps,

Michael N. Mitchell
Data Management Using Stata      - http://www.stata.com/bookstore/dmus.html
A Visual Guide to Stata Graphics - http://www.stata.com/bookstore/vgsg.html
Stata tidbit of the week         - http://www.MichaelNormanMitchell.com



On 2010-08-09 4.05 PM, Kieran McCaul wrote:
...

You need to use the -date- function.

di %d date("17-Mar-85", "DM19Y")

So, if you have dates stored as strings in two variables, date1 and
date2:

gen firstdate = date(date1, "DM19Y")
gen seconddate = date(date2, "DM19Y")
format firstdate seconddate %d

gen n_days = seconddate - firstdate






-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Kirsten Beyer
Sent: Tuesday, 10 August 2010 6:42 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: dates and elapsed time

Hello,

I am relatively new to STATA and have been unsuccessful in formatting
two
dates, then calculating the number of days between them.

Dates are in the following format: 17-Mar-85

Any advice?

KB
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index