Announcement

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

  • Is there an in-script command to save .do files?

    Hello:

    I'm trying to figure out a way to archive local copies of my .do scripts as I run them. At the end of every one of my do files, I want to run a line of code that kicks out a version of the script stamped with the day I was working on it. My current code looks like this:


    Code:
    local today: di %tdCYND date(c(current_date),"DMY")
    
    <body of script>
    
    <dosavecommand> "`archive'\file name `today'.do", replace

    Is there a command built into STATA that allows for me to save the do file?

    Thank you!



  • #2
    Hello Dane,

    Welcome to the Stata Forum.

    I guess you mean:

    Code:
    . save mydofilename, replace
    I kindly suggest you to write Stata (only the first letter is capital) the way it is recommended in the FAQ

    Best,

    Marcos
    Best regards,

    Marcos

    Comment


    • #3
      Hello Marcos,

      Thank you so much!

      I wanted to quickly note that the save command saves my open data set as a do file rather than saving the do file itself. Is there a separate command to save do files?

      Kind regards,
      Dane

      Comment


      • #4
        Hello Dane,

        When typing "mydofilename", please use the extension as well, such as: . save testfile.do, replace.

        Hopefully that helps!

        Best,

        Marcos
        Best regards,

        Marcos

        Comment


        • #5
          Some (considerable potential for) confusion here.

          The save command saves Stata datasets in Stata's proprietary format, usually flagged by a .dta extension.

          Nothing stops you typing

          Code:
          save whatever.do 
          but all you will achieve is to save the dataset in memory, as I have just said. The .do extension does not exert any special magic to save commands to a do-file (which commands would they be?) There is no point to that and it's likely to prove confusing downstream.

          What Dane wants should work as something like

          Code:
          local today: di %tdCYND date(c(current_date),"DMY")  
          copy "this do file.do" "this do file`today'.do", replace
          Last edited by Nick Cox; 10 Dec 2016, 04:25.

          Comment


          • #6
            Nick Cox Thank you for clarifying the issue. Actually, I use to save the do file by clicking on "save" in the menu. However, just trying to provide a solution to #1, I did it by typing on the do-file itself. Indeed, I checked it out, and there it was, in my fold, a new file with a "do" extension, As a consequence, I thought the whole script was safely saved there. Now, I opened the file and, to my dismay - and confusion - , there were blackened typos and "ESC" everywhere. Personally, I didn't feel the need to save do-files by using the commands from the do-file itself. But due to users demands for that, also in the Web under other statistical packages, like R, perhaps such a command, - provided it won't lead to conflicts, and it seems at this point it will, according to your message in #5 - could be part of a wishlist with regards to Stata 15.

            Best,

            Marcos
            Best regards,

            Marcos

            Comment


            • #7
              Marcos: I don't see a need for anything new here and was not trying to suggest that in #5. It seems that you temporarily forgot what save does but there is no deeper issue.

              What the save command does is clearly documented. The common idea of saving any file with whatever it contains needs to be distinguished from the specific command to save a file in .dta format.

              To save (= copy) a particular do-file under a different name, copy is already available.

              To save (= copy) the script currently being executed is problematic, as (1) do files can be nested, so two or more could be running at the same time (2) it is hard to see what that would mean when typed from the Command window.

              Comment


              • #8
                Thank you very much, Nick, for the explanation. Actually, I didn't realized the (problematic and potentially dangerous) issue on saving a script in the end of its execution. Thanks again, Best, Marcos.
                Best regards,

                Marcos

                Comment

                Working...
                X