Hi all,
I always have trouble with dates in Stata and I am wondering if someone can help me unify them and create variables for month, day, year, hour, and minute.
Here are examples of the multiple formats--
2019-10-09 23:09:01
5/16/2021 21:52
Tue, 27 Apr 2021 09:28:55
Here is the code I have been trying but does not work--
gen date_obs = clock(time, "MD20Yhm")
replace date_obs = clock(time, "MD20Yhm")
format date_obs %16.0f
gen month = month(dofc(date_obs))
gen day = day(dofc(date_obs))
gen year = year(dofc(date_obs))
gen hour = hh(date_obs)
gen minute = mm(date_obs)
gen sec = ss(date_obs)
tab month year
tab hour
sort time
Any help would be much appreciated! Thank you!
I always have trouble with dates in Stata and I am wondering if someone can help me unify them and create variables for month, day, year, hour, and minute.
Here are examples of the multiple formats--
2019-10-09 23:09:01
5/16/2021 21:52
Tue, 27 Apr 2021 09:28:55
Here is the code I have been trying but does not work--
gen date_obs = clock(time, "MD20Yhm")
replace date_obs = clock(time, "MD20Yhm")
format date_obs %16.0f
gen month = month(dofc(date_obs))
gen day = day(dofc(date_obs))
gen year = year(dofc(date_obs))
gen hour = hh(date_obs)
gen minute = mm(date_obs)
gen sec = ss(date_obs)
tab month year
tab hour
sort time
Any help would be much appreciated! Thank you!

Comment