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   "Christopher W. Ryan" <>
Subject   Re: st: using pwd in an if statement
Date   Wed, 17 May 2006 10:56:27 -0400

I think I see your point.

Currently, my usual approach is to start Stata, then use the File . . . Do . . . drop-down menu to pick the do-file I want (which is indeed already in the relevant project directory C:/data/scholar/hannah. So this runs, say,, but absent a -cd- near the beginning of, it leaves pwd as C:/data/scholar (what I have it set to as the Stata default). It does not change it to C:/data/scholar/hannah.

It sounds like I should get more in the habit of using the command line, change immediately to the directory of whatever project I am working on, and then get used to using the -do- command.

Christopher W. Ryan, MD
SUNY Upstate Medical University Clinical Campus at Binghamton
and Wilson Family Practice Residency, Johnson City, NY
GnuPG and PGP public keys available at

"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]

Ulrich Kohler wrote:

So if I want to keep everything related to one project (command log,
output log, data) in that project's directory, then my
choices seem to be:

1.  always use full path names
2.  always -cd- to the proper directory at the beginning of a Stata
session (or the beginning of a do-file), using full path name or the
-fastce- package, and then can use relative (short) file names.

Do I have that right?

Almost, I think. I would not recommend to -cd /to/project/directory- at the beginning of a do-file, as you have mentioned within the parentheses of your second point. The do-files belonging to a specific project should be already in the project directory, and you should start them from within that directory. Hence in principal:

. cd /path/to/my/project/directory // <- -fastcd- makes this easier
. do mydo

where contains only relative pathnames:

use xyz, clear //
capture mkdir logetc
capture mkdir graphs
log using logetc/mydo, replace
scatter y x, saving(graphs/mydo_1, replace)
graph export graphs/mydo_1.eps, replace
save mydo, replace
log close


Other strategies might work as well. This one has survived changes from Windows to Linux and Macintosh as well as relocations between Konstanz, Mannheim, Los Angeles, Berlin and Washington.
*   For searches and help try:

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