Announcement

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

  • Is there a way to get the location of a do-file from within that do-file?

    Hi all,

    I'd like to know if there is a way of obtaining the location of a do-file from within that do-file. The use case I'm thinking of is writing a do-file that imports some data located in a constant relative path to the location of that do-file. I'd like to be able to import those data regardless of where the absolute location of the do-file is, as long as the relative location remains the same.

    Thanks,

    Miguel

  • #2
    Unfortunately not. Well, at least not directly, the project command (ssc install project) will does allow a do-file to know where the 'project' is located.

    See:

    https://www.statalist.org/forums/for...being-executed
    https://www.statalist.org/forums/for...-after-do-file
    https://www.statalist.org/forums/for...82#post1450182

    While the use of project likely won't address every use case, I think that your particular case is quite close to project's intended use.
    Last edited by Arthur Morris; 22 Jul 2020, 23:15.

    Comment


    • #3
      Under circumstances similar to yours, I typically have used Stata's change directory command to make my working directory the directory in which the do-file exists. (I'm taking you at your word that you are running a do-file rather than a program in an ado-file.) Then, I just use relative path notation. Assume I have the directory structure
      Code:
      /home/me/mywork
      /home/me/mywork/dofiles
      /home/me/mywork/downloaded
      Code:
      import delimited ../dowloaded/thismonth.csv, clear
      finds its data in the subdirectory "downloaded" which is within the same parent directory as the subdirectory dofiles containing the do-file I am running.

      Comment

      Working...
      X