Announcement

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

  • Set current directory dynamically

    Hello,
    currently I use the command cd to indicate the current directory. However, this approach is static and I would like to ask if it is possible to change it dynamically. I would like to automatically set the folder from which I open and run a do-file to be set as current directory. Therefore, if I send someone my data package (do-file and datasets) the do-file will run without complications and does not output an error message because the directory indicated in the do-file is different. I could not find a solution yet...
    Thanks.

  • #2
    On OS X (and I presume also on Windows) if you execute a do-file either by double-clicking on it (if you have your OS set to open .do files with Stata) or by right-clicking and selecting "Open With Stata" and if you have Stata set to run do-files opened from the OS (instead of editing them), then you'll get the behavior you desire. Specifically, Stata will immediately change its working directory to the location of the do-file before executing it. Thus, if all of the paths in your package are relative to the root of the folder you are distributing (which they should be), and if you put the do-file you want users to execute at the root, everything should just work. Alternatively, its not that difficult to tell users to launch Stata, change directory to the root of your distribution (note that there is a menu command for that so they don't have to use the CLI), and type do myfile.

    Comment


    • #3
      See http://www.stata.com/statalist/archi.../msg01071.html Then, once you have it in the local macro, you can invoke it wherever needed, or just issue a cd command with the local.

      Oh... this doesn't actually solve your problem, since the .do file is in an arbitrary folder. Sorry about the confusion. There isn't a way (short of asking the moderators) to delete a post, or I would.
      Last edited by ben earnhart; 25 Oct 2014, 08:42.

      Comment

      Working...
      X