As the doctor gone rogue

February 16, 2011

Working with date on Stata

Filed under: data management, STATA — Tags: , , — hypotheses @ 3:25 pm

Recently, I received a data coding date, for example, as 8/8/2011 for Aug 8, 2011. When importing this file into STATA, STATA automatically treated this as string. To be able to manipulate “date” easily, I converted it to numeric variable

gen int ndate = date(date, “MDY”)

Then for STATA to display this variable properly in a human readable format

format ndate %td

I, then, I have a question about the mid-visit date, which can now be easily calculated as

mean ndate if visit==2

This gave me number like 18302

Till now, the only way to find out what day this is for me is

display day(18342) month(18342) year(18342)

I think there might be an easier way to split out the DMY format, but I don’t know how yet.

For further information about working in date in STATA, I refer you to the resource on UCLA website, and help files in STATA.



  1. Hi, I like your blog.
    To display the date you can write
    . di %td 18342

    Good luck!

    Comment by Liisa — December 12, 2011 @ 4:20 am

    • Liisa, thank you for the %td tip and for reading.

      Comment by Load OF Kobal — December 12, 2011 @ 3:45 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: