Reputation: 915
The following simple thing doesn't work.
global inputfolder "C:\Users\Focus\Google Drive\1. hani and\Raw data\2004"
cd $inputfolder
It says
invalid syntax
But if I do
global inputfolder "C:\Users"
cd $inputfolder
Then it works. I tried, among others, adding "="
global inputfolder="C:\Users\Focus\Google Drive\1. hani and\Raw data\2004"
but it didn't help.
What should I do to make the first thing work?
Upvotes: 0
Views: 1233
Reputation: 37208
When you write
global inputfolder "C:\Users\Focus\Google Drive\1. hani and\Raw data\2004"
cd $inputfolder
Stata substitutes the global reference with the contents of the global, so that cd
sees
cd C:\Users\Focus\Google Drive\1. hani and\Raw data\2004
but the spaces are then problematic. This advice is prominent in the help for cd
(see e.g. http://www.stata.com/help.cgi?cd):
If your directory_name contains embedded spaces, remember to enclose it in double quotes.
Hence all you need is
cd "$inputfolder"
Note that the difference between copying a string into a global and assigning a string to a global indeed makes no difference here, as the problem is entirely in feeding cd
a string it can't understand.
On a point of terminology, note that global macros are not regarded as variables in Stata. That term is reserved for columns in the dataset.
Upvotes: 4