Announcement

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

  • advice for working with network drives and adopath

    I am working on a windows server and because the work is collaborative, do not wish to use mapped network drives. Thus, I have been using absolute network locations. These pose no problems with commands such as "use" and "save," but I am having trouble with the system directories. I'll show the code but I have to change the names of the directories:

    . local root "\\server\folder"
    . cd `root'
    . adopath + `root'\ado
    . use data\datname.dta, clear

    The command adopath results in the following adopath entry without the two slashes at the front, but rather, only a single slash:

    [7] "\server\folder\ado"

    The use command and the cd command work fine, but Stata cannot find my ado files. Any help is appreciated.

    TIA,
    Kyle

    PS I have also tried

    . adopath + "`root'\ado"

    which produces the same result.
    Last edited by Kyle Hood; 29 May 2020, 16:06.

  • #2
    The backslash character
    Code:
    \
    has meaning to Stata: it will prevent the interpretation of any following character that has a special meaning to Stata, in particular
    Code:
    `
    will not be interpreted as indicating a reference to a macro. And in your case,
    Code:
    \\
    will be interpreted as a single backslash, as you saw, because the first backslash undoes the special meaning of the second backslash.

    One thought that longtime UNIX users will recognize is to increase the number of backslash characters to some power of 2: 2k backslashes in the input will usually yield k backslashes in the output. But that's inelegant.

    There is a more elegant way: Stata will allow you to use the forward slash character in path names on any operating system, and Windows will not object. My understanding is that every version of Windows has accepted "/" as a path separator, and every version of MS-DOS beginning with DOS 2.0 (the first version that had subdirectories). Only in command lines was "/" not allowed, because it had already been used as a switch delimiter in MS-DOS 1.0.

    So change all your backslashes to forward slashes and perhaps it will work. I'm running macOS so I cannot test this advice directly. And if it fails, try the first approach with 22 = 4 backlslashes.
    Last edited by William Lisowski; 29 May 2020, 18:53.

    Comment


    • #3
      So interestingly, I had tried the "//" two forward slashes trick, and what did it do? It commented out the rest of the expression. However, I tried it again, this time with the two forward slashes contained within quotation marks. This has indeed solved the issue. So, the solution is, use forward slashes encased in quotation marks to deal with this problem.

      I also tried using four backslashes. In fact, I did this before posting my original question. It did not work.

      Dr. Lisowski, thank you for the reply.

      Best,
      ​​​​​​​Kyle

      Comment


      • #4
        So interestingly, I had tried the "//" two forward slashes trick, and what did it do? It commented out the rest of the expression.
        If "standup Stata comedy" were a thing, this would be a crowdpleaser. Very well put. The Stata interpretation of // completely escaped me as I focused on Windows.

        I appreciate your taking the time to report that - I'll add it to the notes I keep for questions on backslashes. This is the sort of situation where being a Mac user hampers my ability to work through an answer completely.

        I will add that it is a good habit to enclose filenames within quotes, even in situation where you "know" there are no embedded spaces in any directory name or file name. That way, you don't have to consider the issue each time. Someday someone is going to put a subdirectory or file with an embedded space in the name out on that shared directory with data for you.

        Having said it's a good habit, I'll admit I am myself bad at good habits.
        Last edited by William Lisowski; 30 May 2020, 09:01.

        Comment

        Working...
        X