Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Stata has a rich variety of date and time functions making anything
that you want. See -help dates- for a full introduction. What is below
shows how to start. The help I have referenced shows how to go
. set obs 1
obs was 0, now 1
. gen double datetime = clock("2005-02-19 09:38:00.000", "YMD hms")
. format datetime %tc
| datetime |
1. | 19feb2005 09:38:00 |
On 24 May 2013 10:35, Neophytos Stylianou
> I am using Stata 12.1 and I have a variable containing date and time.
> The problem is that it is a string variable and it contains both date and time within it.
> I want to split them into date variable and time variable but also have the opportunity to have a date time combined variable.
> Example of what the variable contains :
> 2005-02-19 09:38:00.000
> 2005-02-19 09:46:00.000
> I want a variable of date i.e 19/02/2005 and time 09:38:00
> I would do it manually if it was a small number of records but there are more than 1.3million rows
> I know that I can combine the date and time variables which will be created using
> gen double datetime = date*24*60*60*1000 + time
> format datetime %tcNN/DD/CCYY_HH:MM:SS
* For searches and help try: