从Stata中的%tc变量生成年份

时间:2016-07-19 14:03:24

标签: date stata

如何使用此格式09sep1943 00:00:00从Stata变量生成一年并将其存储为%tc组件?

1 个答案:

答案 0 :(得分:4)

这是充分记录的。请参阅help datetime并使用yofd(dofc())

. clear 

. set obs 1
number of observations (_N) was 0, now 1

. gen double datetime = clock("09sep1943 00:00:00", "DMY hms")

. format datetime %tc

. gen year = yofd(dofc(datetime))

. l

     +---------------------------+
     |           datetime   year |
     |---------------------------|
  1. | 09sep1943 00:00:00   1943 |
     +---------------------------+