Announcement

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

  • Is there any way to run the do-files without changing its working directory explicitly

    when working on a project, I, like most people I suppose, save all my data files and do-file under a well structured project directory. At the beginning of each do-file, I change the working directory to my project directory and read and write all files there.
    Code:
    cd "c/Documents/project"
    When collaborating with others on a project, it's usually necessary to send the whole project folder to other people, and most likely they would save the project folder at some directory path different from mine. for example,
    Code:
    D/My Projects/project
    In that case, they would have to change the working directory in each do-file for it to run smoothly.

    Is there any way to run the do-files without changing the directory explicitly? Ideally when they get the project folder, they can just open the do-file and run it, without changing anything.

    What I can think of is at the beginning of the do-file, the do-file somehow gets the path of the do-file and then somehow change all the other paths accordingly. I just don't know how this can be realized. Since the problem is so ubiquitous, I guess there should already be a solution to this? Is it possible to get rid of the absolute paths altogether?

  • #2
    You may want to look at the user written command project
    Jorge Eduardo Pérez Pérez
    www.jorgeperezperez.com

    Comment


    • #3
      read some descriptions about the package, sounds quite promising, thanks Jorge! I'll dig more about it

      Comment


      • #4
        Hi Oliver,

        what I normally do is to create a macro (local or global) that has the working directory path, and then use that all around when needed. That way I don't need to change the working directory, and still access the files from and save them to where I want.

        For example:

        Code:
        local dir "c/Documents/project"
        
        use "`dir'/dataset.dta", clear
        ...
        log using "`dir'/estimations", replace
        ...
        log close
        That way whoever wants to use the do file all (s)he has to do is change the value of the macro to the path (s)he's using in her computer and everything works as a charm.
        Alfonso Sanchez-Penalver

        Comment

        Working...
        X