Dear Stata users,
I want to write a program that allow me to change directory automatically according the filepath of the dataset that I loaded into Stata. I plan to do this in following steps: (1) get the filepath of the file which I am using, I can get it through c(filename); (2) subtract the name of dataset (eg: foo.dta) from string of c(filename), thus the string of "current directory" is left; (3) change directory to current directory using -cd- command.
An example: filepath is "E:\Desktop\Stata Plus\spmap\us_label.dta", subtracting result will be "E:\Desktop\Stata Plus\spmap", and thus I can cd "E:\Desktop\Stata Plus\spmap". I appreciate all your helps. Thank you.
I want to write a program that allow me to change directory automatically according the filepath of the dataset that I loaded into Stata. I plan to do this in following steps: (1) get the filepath of the file which I am using, I can get it through c(filename); (2) subtract the name of dataset (eg: foo.dta) from string of c(filename), thus the string of "current directory" is left; (3) change directory to current directory using -cd- command.
An example: filepath is "E:\Desktop\Stata Plus\spmap\us_label.dta", subtracting result will be "E:\Desktop\Stata Plus\spmap", and thus I can cd "E:\Desktop\Stata Plus\spmap". I appreciate all your helps. Thank you.
Code:
. use "E:\Desktop\Stata Plus\spmap\us_label.dta" . display c(filename) E:\Desktop\Stata Plus\spmap\us_label.dta
Comment