2 cd — Change directory
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 \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
DOS windows under Windows as well.
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 understands ‘
~
’ as an
abbreviation for the home directory, so you can type things like cd
~
/data.