Announcement

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

  • Convert a string variable to a date variable

    I have weekly data as below. Would you please help me convert the string variable to a date variable? Thank you.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 dateid01
    "2018-01-01"
    "2018-01-08"
    "2018-01-15"
    "2018-01-22"
    "2018-01-29"
    "2018-02-05"
    "2018-02-12"
    "2018-02-19"
    "2018-02-26"
    "2018-03-05"
    end

  • #2
    See

    Code:
    help datetime
    for the main ideas.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 dateid01
    "2018-01-01"
    "2018-01-08"
    "2018-01-15"
    "2018-01-22"
    "2018-01-29"
    "2018-02-05"
    "2018-02-12"
    "2018-02-19"
    "2018-02-26"
    "2018-03-05"
    end
    
    gen ddate = daily(dateid01, "YMD") 
    format ddate %td
    The fact that your dates are weekly is not a problem. Just make sure that you declare delta(7) to tsset or xtset.

    Comment

    Working...
    X