[STATA] Converting Dates

As a researcher, I get data with various data formatting- And it was always annoying to convert the dates because I would often forget the codes-

So here I share the codes to convert various string dates to STATA format dates.

  1. Convert DD/MM/YYYY: gen numeric_date=date(string_date, “DMY”)
  2. Convert YYYY-MM-DD or YYYYMMDD: gen numeric_date=date(string_date, “YMD”)

These commands should take care most of the issues-

If you have a numeric YYYYMMDD then use tostring num_date, replace then use the date command.

Don’t forget to format your date.

format numeric_date %d

Another trick is to import the data to excel, which will recognize the dates and then import that excel file to STATA.

Hope this tip saves some time.

Remember our time is limited and are resources are scarce.

Assuming we live about to 80 years, we have 700,800 hrs…so one hour saved is GREAT NEWS!

Thank You Jesus for all Your love and wisdom. Let us always enjoy Your gift of life- Amen!

If you enjoy the content, you can support the blog through clicking the referral links that I use in my life: Acorns, Robinhood, American Express, evernote, and Scribd.

Related Post

Leave a Reply

Your email address will not be published.