Announcement

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

  • Coverting a string date and time variable to date variable

    Hello all,

    I have a variable titled "Trav_Date" in the following format "M/D/YYYY H:MM:SS AM." The variable is a string.

    I want to convert the values to Stata date format and put them into a new variable called "Trav_Date_2."

    The Stata manual has examples of conversions similar to what I want to do, but they don't work.

    For example, I used this:

    generate double Trav_Date_2 = date(Trav_Date, "MDYhms") .

    It runs, but I get "no observations" when I tab the new variable.

    Any help is appreciated!

    (P.S.: I searched the forum, but had no luck in finding an answer.)

  • #2
    It seems that you're mixing the syntax of clock() on the one hand and date() or daily() on the other.

    Code:
    date(word(Trav_Date, 1), "MDY")
    may help.

    Comment


    • #3
      Hello Nick,

      I still get the message "no observations."


      Thanks!

      Last edited by Artur Deguzman; 24 Aug 2023, 18:56.

      Comment


      • #4
        Sorry to hear that, but I have no clear idea what is going on there without a data example. My guess is that your dates don't match what you say. Please follow https://www.statalist.org/forums/help#stata

        Comment

        Working...
        X