Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Function that writes the location of the current do-file ?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Function that writes the location of the current do-file ?
Date   Thu, 1 Jun 2006 22:36:05 +0100

You can pass arguments to a do file. This is 
explicit in the on-line help and explained 
in more detail at [U] 16.6. 

The main idea is that the first, second, 
... argument are mapped to local macros
1, 2, ... . 

So for example 

do frog "c:/project/data" 

could work with 

-------------- frog.do
cd "`1'" 
...
--------------

The successive arguments are delimited 
by white space, except that quotes bind. 

So in 

do frog "c:/windows people prefer long names with spaces"  

"c:/windows people prefer long names with spaces"  

is all the first argument. 

Nick 
n.j.cox@durham.ac.uk 

Sergio Correia
 
> Usually, when writing a do file, the first lines are like this:
> 
> clear
> set mem..
> set more off..
> cd c:/project/data  // !!!!!!
> 
> The problem is that, when using the do files on different computers,
> or giving the data + do-files to a colleague, they have to change each
> do-file to match the location of the data (ie, change cd
> c:/project/data to cd "c:/my documents/john/reviews/data")
> 
> My question is, is there a way to do something like
> 
> cd `currentdofile'
> 
> Where `currentdofile' gives the path to the do file currently running.
> 
> Assuming that the do files are in a folder like 
> c:/project/prg , then I can
> cd ..
> cd data
> 
> And I don't longer have to update locations if the path changes.
> 
> I'm aware that other languages do this, but i don't know if there is
> any way to do this in Stata.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index