Announcement

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

  • Automate file names using current date

    Hi All!

    I'm trying to create a local string reflecting the current date in the format, "YYYY-MM-DD" which I can then concatenate into a file name as such:

    Code:
    use "my_file.YYYY-MM-DD.dta", clear
    I've created a Stata file from a Python code which features the current date in its file name, and I'd like to be able to have Stata automatically use the file so I can run the program from Python without needing to adjust the file name each day.

    Thanks in advance for your help.

    Adam

  • #2
    Code:
    local suffix: display %tdCCYY-NN-DD =daily("`c(current_date)'", "DMY")
    use "my_file.`suffix'.dta", clear
    Note: It is possible to combine the above into a single command, but I think it's just too long and opaque.

    Comment


    • #3
      The display part can be:
      Code:
      display %tdCY-N-D td(`c(current_date)')

      Comment


      • #4
        Thank you very much, Clyde! It worked perfectly!

        Comment

        Working...
        X