Stata: Fail at setting global pathname

早过忘川 提交于 2019-12-13 04:58:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!