In SPSS, one can use FILE HANDLE commands at the top of a syntax file to define paths to folders one wishes to read from or write to. This is useful if the syntax might be used on another computer with a different folder structure: One can modify the FILE HANDLE commands at the top of the file rather than having to find and modify every read & write operation throughout the syntax file.
EDIT: I forgot to include a link to the help for FILE HANDLE. Here it is: http://www.ibm.com/support/knowledge..._overview.html
I was trying to figure out how to achieve that same functionality in Stata. Google searches took me to some old Statalist discussions that suggested using local macros to define paths to folders, like this:
This works perfectly when I run the entire DO-file in one go. However, if I run it piecemeal (which one often does while developing the code), the macro definitions appear to be lost. For example, I get an error message like this when attempting to run one of the use commands part way down the file:
So back to my question: Does Stata have anything like the FILE HANDLE command in SPSS? If not, what is the best way to achieve that same functionality? And can it be done in a way that works even when one runs the DO-file in piecemeal fashion?
Version & OS info: Stata 13.1; Windoze 7 Professional (with SPs)
Thanks,
Bruce
p.s. - Note that I used forward slashes (/) in all of my folder references, so this has nothing to do with the backslash problems with macros noted in one of Nick's SJ articles. It couldn't be that anyway, given that the DO-file works perfectly when I run it all in one go.
EDIT: I forgot to include a link to the help for FILE HANDLE. Here it is: http://www.ibm.com/support/knowledge..._overview.html
I was trying to figure out how to achieve that same functionality in Stata. Google searches took me to some old Statalist discussions that suggested using local macros to define paths to folders, like this:
Code:
// Use local macros to define data and log folders: local datafolder "C:/bw/Stata/IVRMUS/data" local logfolder "C:/bw/LU/PSYC/5151/2016/Stata log files" * Open the log file. * Notice the use of the logfolder macro on the next line: log using "`logfolder'/IVRMUS-04", replace text name(log4) * Open the data file. * Notice the use of the datafolder macro on the next line: use "`datafolder'/gss_ivrm", clear * And so on, with the datafolder macro used throughout.
Code:
. use "`datafolder'/gss_ivrm", clear
file /gss_ivrm.dta not found
r(601);
Version & OS info: Stata 13.1; Windoze 7 Professional (with SPs)
Thanks,
Bruce
p.s. - Note that I used forward slashes (/) in all of my folder references, so this has nothing to do with the backslash problems with macros noted in one of Nick's SJ articles. It couldn't be that anyway, given that the DO-file works perfectly when I run it all in one go.
Comment