How do I reference a data file with a macro?

让人想犯罪 __ 提交于 2019-12-01 23:50:24

This is actually a common error based on a misunderstanding on how local macros in Stata work.

If your local macro datafile is equal to "C:\A and B report\mydata.dta", then the enclosing double quotes are part of the macro definition process and are not present in the stored macro.

To see this:

local datafile = "C:\A and B report\mydata.dta"

macro list _datafile 
_datafile:      C:\A and B report\mydata.dta

Consequently, your use command should instead look as follows:

use "`datafile'", clear

Note that unlike the spaces, which are important, the equal sign (=) is in fact redundant:

local datafile C:\A and B report\mydata.dta

display "`datafile'"
C:\A and B report\mydata.dta
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!