Statalist The Stata Listserver


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

st: RE: using pwd in an if statement


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: using pwd in an if statement
Date   Tue, 16 May 2006 20:59:10 +0100

I think there are three answers here. 

First, use absolute not relative names. 

cd c:\data\scholar\Hannah 

should work so long as you can get there
from wherever you are (including being
there in the first place). 

Second, you are on Windows, but use
forward slashes nevertheless. Stata will
interpret that for you when talking to 
your OS. Otherwise, sooner or 
later you will get bitten by the multiple
interpretation of backward slashes. 

cd c:/data/scholar/Hannah 

Third, -capture- is a command you might
want to learn about.  

Nick 
[email protected] 

Christopher W. Ryan, MD
 
> If I am in a directory, say C:data\scholar\Hannah, and I type
> 
> -cd Hannah-
> 
> I get an error message, as one might expect.
> 
> I am just learning to use .do files for the bulk of my 
> analyses and data 
> manipulations, a la Svend Juul's great book.  I usually try 
> to -cd- to 
> the relevant project directory somewhere near the begining of a .do 
> file, then open the data file.
> 
> But if I am *already in* that directory when I run the .do 
> file, Stata 
> gives the same sort of error:
> 
> cd Hannah
> unable to change to Hannah
> r(170);
> end of do-file
> 
> Is there a way to cd on a conditional basis, such as "if I'm 
> not already 
> in the Hannah directory, then change to it"?  Would this 
> require using 
> something like
> 
> if c(pwd) !=
> 

> Since all of my project files are nested under a single directory for 
> research projects, I suppose I could always put in my 
> do-files a -cd- to 
> that directory before the -cd- to the particular project directory.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index