Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Relative directory paths in Stata?


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Relative directory paths in Stata?
Date   Mon, 5 Aug 2013 09:05:05 +0100

The "current do-file" is not a precisely defined concept given that
do-files can call other do-files and so on.

But you can access the current working directory and parse that.

. di c(pwd)
C:\data

local drive = substr("`c(pwd)'", 1, 2)
cd `drive'

Otherwise your question is also your answer: Use relative paths.
Stata's -cd- is just as smart, if not smarter, than the Windows/DOS
-cd-.

(More generally, always state your operating system if questions
involve it. See the Statalist FAQ on this point.)
Nick
[email protected]


On 5 August 2013 08:49, Mark Millstone <[email protected]> wrote:
> Hi all,
>
> There's one thing I was never able to figure out in Stata. How can I
> instruct the programme to change to the directory which contains the
> current do-file? For instance, if I use a USB stick, depending on the
> computer, I may be working in drive "E:\My files" or "F:\My files".
> Now, if I change the working directory to "F:\My files" in the former,
> or "E:\My files" in the latter case, I will get an error. Can't I just
> instruct Stata to change to whatever directory the current do-file is
> in? Thanks.
>
> Regards,
>
> Mark
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index