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   "Allan Reese (Cefas)" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Relative directory paths in Stata?
Date   Tue, 6 Aug 2013 15:53:05 +0000

This little program godir.ado may be useful. Copy it to your personal ado directory.
Use File/Recent menu to open a datafile in your working directory, and store do files relevant to that data in the same directory.
On the do file editor, I commented long ago that the menu or button force it to open with a blank file, then you can open recent ones. 

GODIR.ADO
program godir
  version 8
  if strpos(reverse("$S_FN"),"/") {
     local lastslash = length("$S_FN")-strpos(reverse("$S_FN"),"/")
   }
   else {
     local lastslash = length("$S_FN")-strpos(reverse("$S_FN"),"\")
   }
  local target = substr("$S_FN", 1,`lastslash')
  if strpos("`target'", ".dta") local target= "`c(pwd)'"
  cd "`target'"
  end
  
and its hlp file:

GODIR.HLP
{smcl}
{* 10sep2001/3nov2004/5oct2007/18dec2009}{...}
{hline}
{cmd:help godir}
{hline}

{title:Title}

{p 4 4 2}{hi:godir} {hline 2} cd to the directory containing the current dataset


{title:Syntax}

{p 8 17 2}
{cmd:godir} 


{title:Remarks} 

{p 4 4 2} Intended to be used when a "recent dataset" has been opened from the file menu.
Saves re-typing the path.


{title:Options}

{p 4 8 2}There are no parameters or options

{title:Acknowledgement}Dan Blanchette  of University of North Carolina provided very helpful advice.

{title:Author}

{p 4 4 2}R Allan Reese{break}
Cefas, Weymouth, U.K.{break} 
[email protected]
-------------------------------------------------------------------------



Date: Mon, 5 Aug 2013 09:49:38 +0200
From: Mark Millstone <[email protected]>
Subject: st: Relative directory paths in Stata?

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


*
*   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