I have various Stata data files. These are located in different folders. I also have a single do
file that uses these files, one at a time.
Is there a way to use a macro to reference a particular dataset in my do
file?
For example:
local datafile = "C:\filepath\mydata.dta"
The idea is to use this later in the code as follows:
use `datafile', clear
Defining the macro as a global variable works. But I don't want to make it global, so it doesn't prevent me from running two separate programs at a time.
The global definition (without the dta
extension) is:
global datafile = "C:\filepath\mydata"
This is used as:
use "$datafile", clear
EDIT:
My file path has spaces like C:\A and B report\mydata.dta
. As a result, with the above local definition I get the following error:
invalid file specification