Announcement

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

  • Default working directory when Stata is launched

    I am using Stata 19 on a Windows computer.

    When I launch Stata on my computer by double-clicking on a Stata-formatted file (.dta, .do, .gph, etc.), the working directory is always the folder in which the file I double-clicked on is stored.

    When I launch Stata from the Windows program menu, the working directory is always my documents folder: C:\Users\rball\Documents

    But when my students are working with Stata, there is some variation in what folder is initially designated as the working directory when Stata is launched.

    When I ask a large group of students to launch Stata by double-clicking on a Stata-formatted file, for most of them the initial working directory is the folder in which the file is stored--which is what I expect. But there are always a few who report that the working directory is initially set to some folder other than the one in which the file is stored--sometimes their downloads folder, sometimes their documents folder, sometimes some other folder that seems completely arbitrary.

    Similarly, when I ask students to launch Stata from the programs menu, it is often the case that, as I expect, the working directory is initially set to their documents folder. But again, there are always a few students for whom the initial working directory is something unexpected.

    At one level, this does not pose a problem: I just tell students that when they launch Stata, they must (i) decide what folder they want to be designated as the working directory, (ii) execute the pwd command to see what folder is initially designated as the working directory, and (iii) if the working directory is not initially set to the folder they chose to be the working directory, then they must change the working directory to the folder they want (either with a cd command, or using the menu: File-->Change working directory... etc.).

    But I would like to be able to explain to them why there is some variation in which folder is initially designated as the working directory when they launch Stata.

    Is their any explanation for the variation I have described?

    ************************************************** ***********
    The above is the general version of my question, but one additional detail might be important: Some of my students use Windows computers and some use Macs. Should we expect Stata's behavior with respect to setting the working directory upon launch to be different on a Mac than on a Windows computer?

  • #2
    There could be several things going on here.
    • the feature that when you double-click a do-file, Stata's working directory is set to the one in which that file is located, was introduced in the Mac version in an update to Stata 17 on 10 January 2023. If a user has a previous version of Stata, or Stata 17 not updated to at least that date, then Stata will instead open in its default location, most likely ~/Documents/Stata on a Mac.
    • The profile.do file, which runs automatically when Stata starts, may for some users, contain commands that change the working directory.
    • On Windows, the Start In field in the Properties sheet for the Stata shortcut can specify the folder in which the program starts.
    This is probably far from an exhaustive list of reasons.

    Comment


    • #3
      In addition to Hemanshu Kumar 's response, I'll also note that, at least on Windows, when you first install a new version of Stata, the installer at one point asks you to select a directory from which Stata should open by default when its icon is double clicked. (The response box comes pre-populated with a default suggestion, but you can overwrite that.) So different choices made during installation can also account for the differences.

      Comment


      • #4
        Thank you to Hemanshu Kumar and Clyde Schechter. Those are very helpful responses to my question--exactly the kind of information I was looking for.

        Comment

        Working...
        X