问题
I have a profile.do
, where it states
global prog "C:\Users\foobar\Google Drive\Cloud\PhD\Projects\Labor Supply\LIAB_QM2_9310_v1_test_dta\prog"
Then I have a different stata different.do
file, where this variable is supposed to be set
adopath ++ $prog
However, this turns to not work out. So I tried to discover the root of the error:
. display $prog
C:\Users\foobar\Google invalid name
Using '
instead of "
didn't help:
. global prog 'C:\Users\sdaro\Google Drive\Cloud\PhD\Projects\Labor Supply\LIAB_QM2_9310_v1_test_dta\prog'
. display $prog
'C:\Users\sdaro\Google invalid name
r(198);
It seems like it's trying to replace Drive
with something, but I don't get what. How can I fix this issue?
回答1:
Your path has blanks, so you need surrounding quotes. The quotes used when defining the macro are meant to be delimiters. When invoked, display
and adopath
will strip them out.
global prog "C:\Users\foobar\Google Drive\Cloud\PhD\Projects\Labor Supply\LIAB_QM2_9310_v1_test_dta\prog"
display "$prog"
adopath ++ "$prog"
If you're not allowed to change adopath $prog
, you can protect the original quotes with double quotes:
global prog ""C:\Users\foobar\Google Drive\Cloud\PhD\Projects\Labor Supply\LIAB_QM2_9310_v1_test_dta\prog""
display $prog
adopath ++ $prog
Notice the original error you received:
. display $prog
C:\Users\foobar\Google invalid name
Because you didn't use quotes, Stata assumed a variable name, and what you have there is an illegal name (can't have :
or \
or blanks).
来源:https://stackoverflow.com/questions/31626827/stata-fail-at-setting-global-pathname