Announcement

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

  • Project Manager and current/working directory

    Is there a way to make it so that when I open a project (*.stpr) from within Stata, the current directory is automatically updated to the project directory (i.e., the directory with the stpr file in it)?

    It does not do this for me (Windows 10), which is a little awkward and hampers portability.
    If I open the stpr file directly from Windows without first opening Stata, then it does start in that directory (as Stata does if you double-click a do-file before starting Stata).

    Might seem silly, but if I switch between projects without closing the Stata application, then I have to navigate around to the new project folder, and I am really very lazy.

    Sorry if I missed a thread about this, but could not find much about project manager in the forum.
    I use Stata/SE 16.1 for Windows (64 bit).

    Thanks,
    Scott

  • #2
    The short answer is no. Stata is not able to pull the directory where the current file is located.

    The slightly boring workaround could be to use an -if- statement to choose the path based on setting a local macro. This would be placed near the top of your do file. For example,

    Code:
    local which_system home
    
    local path
    if "`which_system'"=="home" {
      local path "home path here"
    }
    else if ....

    Comment


    • #3
      Thanks Leonardo.
      Good to know I was not missing some setting. We do have a method of macros to set file paths something like you suggest-- really a separate short do-file that just sets some global macros for paths needed throughout the other project do-files. A little messy but workable.

      As an aside, (I find this an issue in R as well--) basically the idea that all the code and data will be in one 'project folder' -- is not realistic. Source data might be in a repository on a network outside of the project folder with a very difficult relative path that might not be easy to predict depending on where the user is sitting (" ../../../repository/project x/database_09Jul2020/... etc"). This is especially true when code is shared via a GitHub repository with collaborators around the world. My group is working towards a system of internet-accessible databases to query (e.g., with ODBC) but not quite there yet, in part due to global collaborators across institutions, presenting challenges with firewalls, transmitting PHI, etc. Trying very hard to get away from "email the data file to me..."

      More and more often, data management goes way beyond loading a local file and maybe merging a few files, so finding good tools for that is very helpful. Probably there are some out there that I am not aware of, so any suggestions welcome. I was hoping the project manager would be more powerful, perhaps it could be in future (allow transparent connection to ODBC data sources? transparent import of non-Stata file types such as Excel and csv? more active or intuitive file path management?).
      Admittedly I do not know exactly the solution I am looking for and these are just my two-cent thoughts while working on other tasks and running up against data- and code-sharing challenges.

      Best Regards,
      Scott

      Comment


      • #4
        Originally posted by Scott Adams View Post
        Thanks Leonardo.
        Good to know I was not missing some setting. We do have a method of macros to set file paths something like you suggest-- really a separate short do-file that just sets some global macros for paths needed throughout the other project do-files. A little messy but workable.
        This is ultimately what I would envision to be used, and everyone in the project can maintain their own "path" file, if necessary. One of the main reasons, I think, that Stata (nor R by similar analogy) can offer this feature is because snippets of code can be run from within a do-file, which triggers the creation of writing a temporary text file with just those commands, and then executing it. Surely the path of that temporary file is not useful, and Stata was never really aware of its origins. Then with having multiple files open in a project or do-file editor, the problem can be compounded. I prefer the approach in #2 because it spells out (just once) where things are located so there isn't any confusion. On the other hand, if you move the file, then relative paths made from that file simply break and it may not be immediately clear why.

        Comment

        Working...
        X