String 将字符串转换为Stata中的时间
我的Stata文件中有以下字符串格式的时间戳。如何将其转换为时间格式 数据采用HH:MM:SS格式,后面还有一个“.000000”String 将字符串转换为Stata中的时间,string,time,format,stata,String,Time,Format,Stata,我的Stata文件中有以下字符串格式的时间戳。如何将其转换为时间格式 数据采用HH:MM:SS格式,后面还有一个“.000000” 在这里,标准代码的唯一扭曲之处在于,显然需要忽略隐含的微秒精度。这里的代码仅以精确秒为例。如果确实具有毫秒精度,请使用字符串中的更多字符 . clear . input str15 stime stime 1. "21:17:47.000000" 2. "17:30:14.000000" 3. "10:09:44.0
在这里,标准代码的唯一扭曲之处在于,显然需要忽略隐含的微秒精度。这里的代码仅以精确秒为例。如果确实具有毫秒精度,请使用字符串中的更多字符
. clear
. input str15 stime
stime
1. "21:17:47.000000"
2. "17:30:14.000000"
3. "10:09:44.000000"
4. "09:24:32.000000"
5. "15:17:41.000000"
6. end
. gen double ntime = clock(substr(stime, 1, 8), "hms")
. format ntime %tcHH:MM:ss
. list
+----------------------------+
| stime ntime |
|----------------------------|
1. | 21:17:47.000000 21:17:47 |
2. | 17:30:14.000000 17:30:14 |
3. | 10:09:44.000000 10:09:44 |
4. | 09:24:32.000000 09:24:32 |
5. | 15:17:41.000000 15:17:41 |
+----------------------------+
你试过什么代码?没有明显的研究成果。
. clear
. input str15 stime
stime
1. "21:17:47.000000"
2. "17:30:14.000000"
3. "10:09:44.000000"
4. "09:24:32.000000"
5. "15:17:41.000000"
6. end
. gen double ntime = clock(substr(stime, 1, 8), "hms")
. format ntime %tcHH:MM:ss
. list
+----------------------------+
| stime ntime |
|----------------------------|
1. | 21:17:47.000000 21:17:47 |
2. | 17:30:14.000000 17:30:14 |
3. | 10:09:44.000000 10:09:44 |
4. | 09:24:32.000000 09:24:32 |
5. | 15:17:41.000000 15:17:41 |
+----------------------------+