Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Break lengthy path name

    Hi all,

    I was wondering whether there is a way to "break" a rather lengthy path name. I have tried several things that came to mind, although none of them worked. I have tried:
    Code:
    #delimit ;
    global rawdata "C:/Users/xxxx/OneDrive/OneDrive - University of Edinburgh/"
                          "xxxxxx/xxxxxr/xxxxx" ;
    Code:
    global rawdata "C:/Users/xxxx/OneDrive/OneDrive - University of Edinburgh/ ///
                           xxxxxx/xxxxxr/xxxxx"
    Code:
    global rawdata "C:/Users/xxxx/OneDrive/OneDrive - University of Edinburgh/
                           xxxxxx/xxxxxr/xxxxx"
    Basically I am trying to fit within 80 columns that global macro. I have "anonymised" some bits of the path, but I have left the "OneDrive - University of Edinburgh" as it is because I have the suspicion that the "-" is causing some problem, somehow.

    The first option gives no syntax error, and when I use "display" the path is displayed properly. However, if I then do:
    Code:
    use "$rawdata/xxxx.dta", clear
    Stata complains that "xxxxxx/xxxxxr/xxxxx/xxxx.dta" is invalid---which suggests that Stata is not taking the whole path, but the second line after the break. Perhaps because Stata thinks there is a "space" between "...Edinburgh/" and "xxxxxx...."

    Any idea would be great. Is it possible (breaking a path name) at all? Thank you!!

  • #2
    You need to use compound double quotes when there are embedded spaces in the string referenced by the macro.

    Comment


    • #3
      Compound quotes aren't going to help in this case, I don't think. The issue is getting the syntax right for breaking the global across lines. This should work:
      Code:
      global rawdata "C:/Users/xxxx/OneDrive/OneDrive - University of Edinburgh/" ///
       "xxxxxx/xxxxxr/xxxxx"


      another option would be:
      Code:
      global rawdata "C:/Users/xxxx/OneDrive/OneDrive - University of Edinburgh/"
      global rawdata "${rawdata}/xxxxxx/xxxxxr/xxxxx"

      Comment


      • #4
        Hi both,

        Sorry for not having replied as yet---thought I did.

        Sarah's second solution works just fine (the first one does not, though). Some explanation: the command "display" seems to display properly the path name (no matter which way of Sarah's post you use). However, the first way "breaks" subsequent commands. For instance:

        Code:
        global rawdata "C:/Users/xxxx/OneDrive/OneDrive - University of Edinburgh/" ///
        "xxxxxx/xxxxxr/xxxxx"
        
        display "$rawdata"
        
        log using $rawdata/example, replace text
        In this case Stata complains when attempting to start a log file that "-" is invalid. If you use Sarah's second way everything seems to work.

        Thanks for your help, by the way.

        Comment

        Working...
        X