Often we get dates are in a form of a string. When you try to convert to a numeric date, it may quite annoying. However, with a simple date function, your life will be simpler and much blessed.
A: Use the “date” function.
**Put the string_date variable first and then put the format that it is in. “D”=Day, “M”=Month, and “Y”=Year
gen numeric_date=date(string_date, “DMY”)
**To make the date readable, use “format”
format %d numeric_date
***Let’s see it in action
clear
set obs 1
gen string_date=”11/10/2016″
gen string_date1=”11oct2016″
gen numeric_date=date(string_date, “DMY”)
gen numeric_date1=date(string_date, “DMY”)
format %d numeric_date numeric_date1