Title stata.com
cd Change directory
Description Quick start Syntax Remarks and examples Also see
Description
Stata for Windows: cd changes the current working directory to the specified drive and directory.
pwd is equivalent to typing cd without arguments; both display the name of the current working
directory. Note: You can shell out to a Windows command prompt; see [D] shell. However, typing !cd
directory name does not change Stata’s current directory; use the cd command to change directories.
Stata for Mac and Stata for Unix: cd (synonym chdir) changes the current working directory to
directory name or, if directory name is not specified, the home directory. pwd displays the path of
the current working directory.
Quick start
Change working directory in Stata for Windows to C:\mydir\myfolder
cd c:\mydir\myfolder
Change working directory in Stata for Windows to C:\my dir\my folder
cd "c:\my dir\my folder"
Change working directory in Stata for Mac or Unix to mydir/myfolder
cd mydir/myfolder
Move up one level in the directory structure
cd ..
Move to myfolder from mydir
cd myfolder
View current working directory
pwd
Go to home directory in Stata for Mac or Unix
cd
1
2 cd Change directory
Syntax
Stata for Windows
cd
cd
"
directory name
"
cd
"
drive:
"
cd
"
drive:directory name
"
pwd
Stata for Mac and Stata for Unix
cd
cd
"
directory name
"
pwd
If your directory name contains embedded spaces, remember to enclose it in double quotes.
Remarks and examples stata.com
Remarks are presented under the following headings:
Stata for Windows
Stata for Mac
Stata for Unix
Stata for Windows
When you start Stata for Windows, your current working directory is set to the Start in directory
specified in Properties. If you want to change this, see [GSW] B.1 The Windows Properties Sheet.
You can always see what your working directory is by looking at the status bar at the bottom of the
Stata window.
Once you are in Stata, you can change your directory with the cd command.
. cd
c:\data
. cd city
c:\data\city
. cd d:
D:\
. cd kande
D:\kande
. cd "additional detail"
D:\kande\additional detail
. cd c:
C:\
. cd data\city
C:\data\city
cd Change directory 3
. cd \a\b\c\d\e\f\g
C:\a\b\c\d\e\f\g
. cd ..
C:\a\b\c\d\e\f
. cd ...
C:\a\b\c\d
. cd ....
C:\a
When we typed cd d:, we changed to the current directory of the D drive. We navigated our
way to d:\kande\additional detail with three commands: cd d:, then cd kande, and then
cd "additional detail". The double quotes around “additional detail” are necessary because of
the space in the directory name. We could have changed to this directory in one command: cd
"d:\kande\additional detail".
Notice the last three cd commands in the example above. You are probably familiar with the
cd .. syntax to move up one directory from where you are. The last two cd commands above let you
move up more than one directory: cd ... is shorthand for cd ..\.. and cd .... is shorthand
for cd ..\..\..”. These shorthand cd commands are not limited to Stata; they will work in your
Command window under Windows as well.
You can see the current directory (where Stata saves files and looks for files) by typing pwd. You
can change the current directory by using cd or by selecting File > Change working directory....
Stata’s cd command understands
~
as an abbreviation for the home directory, so you can type things
like cd
~
\data.
. pwd
C:\Users\bill\proj
. cd "
~
\data\city"
C:\Users\bill\data\city
.
If you now wanted to change to "C:\Users\bill\data\city\ny", you could type cd ny. If you
wanted instead to change to "C:\Users\bill\data", you could type cd ..”.
Stata for Mac
Read [U] 11.6 Filenaming conventions for a description of how filenames are written in a command
language before reading this entry.
Invoking an application and then changing folders is an action foreign to most Mac users. If it is
foreign to you, you can ignore cd and pwd. However, they can be useful. You can see the current
folder (where Stata saves files and looks for files) by typing pwd. You can change the current folder
by using cd or by selecting File > Change working directory.... Stata’s cd command understands
~
as an abbreviation for the home directory, so you can type things like cd
~
/data.
. pwd
/Users/bill/proj
. cd "
~
/data/city"
/Users/bill/data/city
.
If you now wanted to change to "/Users/bill/data/city/ny", you could type cd ny. If you
wanted instead to change to "/Users/bill/data", you could type cd ..”.
4 cd Change directory
Stata for Unix
cd and pwd are equivalent to Unix’s cd and pwd commands. Like csh, Stata’s cd understands
~
as an abbreviation for the home directory $HOME, so you can type things like cd
~
/data; see
[U] 11.6 Filenaming conventions.
. pwd
/usr/bill/proj
. cd
~
/data/city
/usr/bill/data/city
.
If you now wanted to change to /usr/bill/data/city/ny, you could type cd ny. If you wanted
instead to change to /usr/bill/data, you could type cd ..”.
Also see
[D] copy Copy file from disk or URL
[D] dir Display filenames
[D] erase Erase a disk file
[D] mkdir Create directory
[D] rmdir Remove directory
[D] shell Temporarily invoke operating system
[D] type Display contents of a file
[U] 11.6 Filenaming conventions
Stata, Stata Press, and Mata are registered trademarks of StataCorp LLC. Stata and
Stata Press are registered trademarks with the World Intellectual Property Organization
of the United Nations. StataNow and NetCourseNow are trademarks of StataCorp
LLC. Other brand and product names are registered trademarks or trademarks of their
respective companies. Copyright
c
19852023 StataCorp LLC, College Station, TX,
USA. All rights reserved.
®
For suggested citations, see the FAQ on citing Stata documentation.