Announcement

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

  • batch validation of Stata Date/Time field, after conversion from string Date/Time

    Greetings,
    I have created a Stata Date/Time variable by converting a string variable displayed as MM/DD/YY 00:00. My code is as follows:
    HTML Code:
    gen new_eventime1 = clock(eventime1, "MDYhm")
    gen new_eventime2 = clock(eventime2, "MDYhm")
    gen new_eventime3 = clock(eventime3, "MDYhm")
    format new_eventime* %tcDDmonCCYY_HH:MM
    I then pilot tested validation by typing:
    HTML Code:
    l eventime1 new_eventime1 
    l eventime2 new_eventime2 
    l eventime3 new_eventime3
    As I have many variables to validate, is there a batch method, for example using something analagous to
    HTML Code:
    assert
    ?

  • #2
    I haven't checked this (lacking sample data) but it might at least be a starting point:
    Code:
    assert eventime1==string(new_eventime1,"%tcNN/DD/YY_HH:MM")

    Comment


    • #3
      Not sure why you'd want to do this "validation" (what result are you looking for / concerned about?) but the first thing you need to do is create the new variable as a double:
      gen double new_eventime1 = clock(eventime1, "MDYhm")
      See help datetime

      Comment

      Working...
      X