

While the four date variables you've created are perfectly functional dates as far as Stata is concerned, they're difficult for humans to interpret. Gen date4=mdy(month,day,year) Formatting Date Variables It takes three numeric arguments: the month, day and year to be converted. To convert such dates to Stata dates, use the mdy function. The year, month and day variables in the example data set contain the same date as the others but in this format.

Converting Numbers to DatesĪnother common scenario gives you dates as three separate numeric variables, one for the year, one for the month and one for the day. To convert them to Stata dates do the following: This is an example data set containing the above dates as dateString1, dateString2 and dateString3. To see this in action, type (or copy and paste) the following into Stata: If you are interested in tracking the time of day you need to switch to the clock function and the %tc format so time is measured in milliseconds rather than days, but they are very similar. A date like " 08:35:12" requires the mask YMD# so that the last three numbers are skipped. Thus the mask MDY means "month, day, year" and can be used to convert both "November 3, 2010" and "". In a date mask, Y means year, M means month, D means day and # means an element should be skipped.
UTIME FOR DATES BEFORE 1960 SERIES
The date function takes two arguments, the string to be converted, and a series of letters called a "mask" that tells Stata how the string is structured. If you've been given a date in string form, such as "November 3, 2010", "" or " 08:35:12" it can be converted using the date function. Often the first task is to convert the data you've been given into official Stata dates.
UTIME FOR DATES BEFORE 1960 HOW TO
This article will focus on days, but if you know how to work with days you can quickly learn the others.

Stata has similar tools that measure time in terms of milliseconds, months, quarters, years and more. This article will introduce you to some of the most useful and easy to use features.Ī Stata date is simply a number, but with the %td format applied Stata will interpret that number as "number of days since January 1, 1960." You can then use that number in a variety of ways. Stata has many tools for working with dates.
