全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
5532 5
2013-07-13
万分感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-7-13 12:24:58
用encode命令即可将原格式日期数据转成数值型:encode a, generate(b)。斜体为变量名
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-13 13:32:32
Title

    [D] datetime translation -- String to numeric date translation functions


Syntax

    The string-to-numeric date and time translation functions are

            Desired SIF type  |  String-to-numeric translation function
            ------------------+---------------------------------------
            datetime/c        |        clock(HRFstr, mask [, topyear])
            datetime/C        |        Clock(HRFstr, mask [, topyear])
                              |
            date              |         date(HRFstr, mask [, topyear])
                              |
            weekly date       |       weekly(HRFstr, mask [, topyear])
            monthly date      |      monthly(HRFstr, mask [, topyear])
            quarterly date    |    quarterly(HRFstr, mask [, topyear])
            half-yearly date  |   halfyearly(HRFstr, mask [, topyear])
            yearly date       |       yearly(HRFstr, mask [, topyear])
            ----------------------------------------------------------

    where

        HRFstr is the string value (HRF) to be translated,

        topyear is described in Working with two-digit years, below,

        and mask specifies the order of the date and time components and is a string composed of a sequence of these elements:

            Code  | Meaning
            ------+---------------------------------------
             M    | month
             D    | day within month
             Y    | 4-digit year
             19Y  | 2-digit year to be interpreted as 19xx
             20Y  | 2-digit year to be interpreted as 20xx
                  |
             h    | hour of day
             m    | minutes within hour
             s    | seconds within minute
                  |
             #    | ignore one element
            ----------------------------------------------

        Blanks are also allowed in mask, which can make the mask easier to read, but they otherwise have no significance.

        Examples of masks include

            "MDY"      HRFstr contains month, day, and year, in that order.

            "MD19Y"    means the same as "MDY" except that HRFstr may contain two-digit years, and when it does, they are to be treated as if they are
                       4-digit years beginning with 19.

            "MDYhms"   HRFstr contains month, day, year, hour, minute, and second, in that order.

            "MDY hms"  means the same as "MDYhms"; the blank has no meaning.

            "MDY#hms"  means that one element between the year and the hour is to be ignored.  For example, HRFstr contains values like "1-1-2010 at
                       15:23:17" or values like "1-1-2010 at 3:23:17 PM".


Description

    These functions translate dates and times recorded as strings containing human readable form (HRF) to the desired Stata internal form (SIF).  See [D]
    datetime for an introduction to Stata's date and time features.

    Also see Using dates and times from other software in [D] datetime.


Remarks

    Remarks are presented under the following headings:

            Introduction
            Specifying the mask
            How the HRF-to-SIF functions interpret the mask
            Working with two-digit years
            Working with incomplete dates and times
            Translating run-together dates, such as 20060125
            Valid times
            The clock() and Clock() functions
            Why there are two SIF datetime encodings
            Advice on using datetime/c and datetime/C
            Determining when leap seconds occurred
            The date() function
            The other translation functions


    Introduction

    The HRF-to-SIF translation functions are used to translate string HRF dates, such as "08/12/06", "12-8-2006", "12 Aug 06", "12aug2006 14:23", and "12
    aug06 2:23 pm", to SIF.  The HRF-to-SIF translation functions are typically used after importing or reading data.  You read the date information into
    string variables and then the HRF-to-SIF functions translate the string into something Stata can use, namely, an SIF numeric variable.

    You use generate to create the SIF variables.  The translation functions are used in the expressions, such as

        . generate double time_admitted = clock(time_admitted_str, "DMYhms")
        . format time_admitted %tc

        . generate date_hired = date(date_hired_str, "MDY")
        . format date_hired %td

   
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-16 08:52:58
lyrasover 发表于 2013-7-13 12:24
用encode命令即可将原格式日期数据转成数值型:encode a, generate(b)。斜体为变量名
嗯嗯,十分谢谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-16 08:54:33
蓝色 发表于 2013-7-13 13:32
Title

    [D] datetime translation -- String to numeric date translation functions
多谢多谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-18 00:27:41
It's good for me. Thanks~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群