Would it be possible, when I launch a do-file to recover the path of the do-file as a variable?
I'm sharing a project with a co-author (via Dropbox). The structure of the folders (data, logs, etc.) is therefore the same on both sides.
But the folders are situated differented on my coauthor's filesystem and mine. It would therefore be helpful for us to write do-file that are agnostic about the path of the folders, etc.
We would like the path to our projects not to be hard-coded.
Thank you!
You can do various things in this territory, including
Passing the name of a directory to a do-file as an argument. For example,
do mydo d:/myproject/data1812
launches the file mydo.do
and passes the argument of a particular directory to the do-file. Inside the do-file you can grab the argument as
local myfolder "`1'"
i.e. the thing passed is passed as local macro 1. (Any other arguments would be local macros 2, 3, etc.)
Make sure your references to locations generally and files in particular are relative within the do-file and run the do-file from the parent directory.
Use global macros within your main do-file for locations and then re-define them within a master do-file which you run first.
Notes: It's best to use forward slashes, even under Windows; Stata will translate. Also, if there are embedded spaces, bind the whole thing in double quotes.
do mydo "d:/my project/data1812"
The second seems closest to your preference for not wiring in particular locations. But if you are using files from different places you have to tell Stata somehow where they are....