Changing default directory in Stata | Johan Osterberg - Product Engineer

Changing default directory in Stata

March 30, 2019

Whenever you have modified a dataset in Stata that you want to save you need to do so explicitly, otherwise it will just be cleared from memory. When you do save a dataset it gets saved to the default directory, which can be located with the cd command. In my case on a Windows 10 machine this points to C:\Users\USER_NAME\Documents. If you dont want to clutter your Documents folder with various datasets you can just change default directory, like so:

md Stata\datasets
cd Stata\datasets
sysuse census, clear
save census-dupl

Now a copy of the census.dta named census-dupl.dta gets saved to the new custom directory instead of the default one.


Profile picture

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin

2024 © Johan Osterberg