Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • decompose %tc variable into components

    Hi, I am not able to decompose the eventtime_1 into hour, day, month, and year components.

    I have created eventime_1 variable:

    gen a=dUTC*60*60000
    gen double eventtime_`i'=round(eventtime+a,60000)

    eventtime_1

    08feb1990 18:30:00
    28mar1990 19:30:00
    16may1990 18:30:00
    05jul1990 18:30:00
    13jul1990 18:30:00
    22aug1990 18:30:00
    03oct1990 17:30:00
    29oct1990 18:30:00
    14nov1990 18:30:00
    07dec1990 18:30:00

    describe eventtime_1

    storage display value
    variable name type format label variable label
    -----------------------------------------------------------------------------------------------------------------------
    eventtime_1 double %tc


    and I want to decompose eventtime_1 into its components . for example for the first row, I would like to create 4 variables:


    hour: 18:30
    day:08
    month:mar or 3
    year:1990

    I would really appreciate your help...


  • #2
    The functions you need are all specified under help dates and times.The year for example is extracted by yofd(dofc()). However, it is not clear how you want to hold the hour. That's just another date-time, unless you want a string variable representation.

    Comment


    • #3
      There are several function that allow you to extract the components: hh() for hours, and mm() for minutes, day(dofc()) for day month(dofc()) for month and year(dofc()) for year. This is documented in help datetime.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment

      Working...
      X