Announcement

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

  • Transform string to date failed

    Please help me to transform the "date" variable to real date form "YYYYMMDD". I have tried everything but failed. Really don't know why. The data file is attached.

    Thank you!
    Attached Files

  • #2

    .ÿgenerateÿintÿdate_dtÿ=ÿdate(date,ÿ"MDY")

    .ÿformatÿdate_dtÿ%tdCY-N-D

    .ÿlÿdateÿdate_dtÿinÿ1/2

    ÿÿÿÿÿ+---------------------------+
    ÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿdateÿÿÿÿÿÿdate_dtÿ|
    ÿÿÿÿÿ|---------------------------|
    ÿÿ1.ÿ|ÿAprÿ01,ÿ1983ÿÿÿ1983-04-01ÿ|
    ÿÿ2.ÿ|ÿAprÿ01,ÿ1985ÿÿÿ1985-04-01ÿ|
    ÿÿÿÿÿ+---------------------------+

    .


    What did you try?

    Comment


    • #3
      Originally posted by Joseph Coveney View Post

      .ÿgenerateÿintÿdate_dtÿ=ÿdate(date,ÿ"MDY")

      .ÿformatÿdate_dtÿ%tdCY-N-D

      .ÿlÿdateÿdate_dtÿinÿ1/2

      ÿÿÿÿÿ+---------------------------+
      ÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿdateÿÿÿÿÿÿdate_dtÿ|
      ÿÿÿÿÿ|---------------------------|
      ÿÿ1.ÿ|ÿAprÿ01,ÿ1983ÿÿÿ1983-04-01ÿ|
      ÿÿ2.ÿ|ÿAprÿ01,ÿ1985ÿÿÿ1985-04-01ÿ|
      ÿÿÿÿÿ+---------------------------+

      .


      What did you try?
      I tried gen date1=date(date,"MDY")
      but only generate missing values

      Comment


      • #4
        Seeing a .csv file is not definitive as we need to know what the data look in Stata. When I used db import delimited the dates were imported as string but @Joseph Coveney's syntax worked fine.

        For future posts please read and act on all of https://www.statalist.org/forums/help#stata including giving data examples and the exact code you used, and not other files.
        Last edited by Nick Cox; 11 May 2019, 08:36.

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Seeing a .csv file is not definitive as we need to know what the data look in Stata. When I used db import delimited the dates were imported as string but @Joseph Coveney's syntax worked fine.

          For future posts please read and act on all of https://www.statalist.org/forums/help#stata including giving data examples and the exact code you used, and not other files.
          Thank you!

          Comment

          Working...
          X