Statalist The Stata Listserver


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

Re: st: using pwd in an if statement


From   Nick Winter <nw53@cornell.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: using pwd in an if statement
Date   Tue, 16 May 2006 15:59:27 -0400

The package -fastcd- on SSC has a utility called -c- designed for just this sort of issue. It allows you to set up a set of associations between directory and mnemonics-- such as "hannah" for "C:\data\scholar\Hannah", and so on. Then you can type "c hannah" and you will be switched to that directory.

The package name is fastcd; once you install the package, note that you have to type

. help fastcd

for help. The command, howver, is "c". This is a side effect of me naming the command a single letter--something Stata advises against. Stata has subsequently taken back "help c" to point to help on the c() macros.


--Nick Winter



At 03:49 PM 5/16/2006, you wrote:

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.

--
Christopher W. Ryan, MD
SUNY Upstate Medical University Clinical Campus at Binghamton
and Wilson Family Practice Residency, Johnson City, NY
cryanatbinghamtondotedu
GnuPG and PGP public keys available at http://pgp.mit.edu

"If you want to build a ship, don't drum up the men to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea." [Antoine de St. Exupery]

*
* 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/
--------------------------------------------------------
Nicholas Winter                           607.255.8819 t
Assistant Professor                       607.255.4530 f
Department of Government              nw53@cornell.edu e
308 White Hall            falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601


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