Announcement

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

  • Saving do-files on a Mac

    This is a pretty basic question, but I'm a teaching assistant for econometrics right now and a student asked me about it, reminding me that I had never figured it out myself.

    The students are given specific instructions to save their do-files with a line at the end of the do-file reading something like:
    save "$datadir\saving do-files.do", replace

    However, on Macs (at least for several people, including me), once this saved do-file is re-opened, it is empty except for one line of gibberish:
    <stata_dta><header><release>117</release><byteorder>LSF</byteorder><K>

    That's an exact quote, and there's nothing else in it. This happens no matter whether I use the $datadir global macro or write in the whole pathway. I've been trying to find instructions or solutions and can't find anything.

    Any help would be greatly appreciated! Is it possible that this line just doesn't work in Macs? Is there another way to include a save command within the do-file?

    Thanks,

    Kristen

  • #2
    Kristen: I am puzzled by your problem description. You refer to wanting to save a do-file using the code
    Code:
    save "$datadir\saving do-files.do", replace
    What that command line will do is save the current dta file to disk, but with extension .do (or maybe .do.dta -- I don't know, as not a Mac user).

    So, are you asking about how to get students to save their updated data files, or to save the do-file with which they've been working? It's the latter that's particularly important.

    It's good practice to ensure students learn to run data management and analysis using do-files -- as you are teaching them. Remember also to ensure that they maintain a copy of the original data set. Otherwise, once modified and saved, there's no going back.

    One way of working is to experiment using menu commands (not saving the data) while, at the same time, building up a do-file, that can then be run at the end and re-do the whole chain of (successful and desired) commands . [Stata's do-file editor is sufficient for most student purposes.]

    You might want to have a look some old materials of mine presented at a couple of internal presentations: ‘Workshops on ‘Audit trails, reproducibility and output processing’ and ‘Effective use of Stata graphics’’ http://www.iser.essex.ac.uk/files/te...ps-Jenkins.zip. The first file in the archive is particularly relevant in your case.


    Comment


    • #3
      As a Mac user, I can confirm that the command saves the data to disk with a .do extension instead of a .dta extension, and with a filename that begins with the unfortunate backslash. On a Mac, at least, it seems the preferred syntax would be save ${datadir}filename or something similar.

      Because of the .do extension, opening the file in Stata on the Mac causes it to appear in the do-file editor, which only displays the initial header line in the file. However, the file is indeed the complete data, and changing the extension from .do to .dta results in the file being treated as the data file it is.

      I'd be interested in knowing what happens on Windows systems when the recommended advice is followed. My guess is that on Windows, Stata may not rely on the extension to determine that the saved file is a data file rather than a do file, so that when it's opened subsequently, it is treated as data. But still, the instructions as reported seem incompletely thought out, and that's being generous.

      Comment


      • #4
        That's helpful, thanks to both of you. And thank you for the materials Stephen, they will be very useful! I think the instructions were written originally by a PC user, and perhaps were never adjusted for Macs; I haven't had any PC users present difficulties with this. I guess I'll tell Mac users to save differently.

        Comment


        • #5
          Kristen, this has nothing to do with the platform.

          Whether on Mac, or on PC, or on any other platform, Stata's save command saves data.

          One can start do editor programmatically with the doedit command and even supply a filename to be opened for editing.

          There is no official command to save the do file currently in the doeditor. This action is only available from the menu/toolbar. It is not automatable (not callable from the do-file itself).
          Workaround for this would probably be more complicated than you want your students to get involved.
          Similarly like a do file doesn't know its own name, it can't save itself either.

          Best, Sergiy Radyakin

          Comment

          Working...
          X