Announcement

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

  • STATA seems to add spaces into path where there are none although using double quotes

    Dear statalist,

    I am using Stata/SE 15.1 for Mac. I am using a global to specify my path at the beginning of my do file. I write it like this:
    Code:
    global path "/Users/felix/Dropbox⁩/Felix⁩/F&Vs PHD⁩/EINITE⁩/Aggregation⁩/Paper⁩/Aggregation_21082019⁩/"
    However, in the command window Stata returns it like this, with additional spaces, e.g. after "felix":
    Code:
    global path "/Users/felix ⁩/Dropbox ⁩/Felix⁩/F&Vs PHD ⁩⁩/ ⁨EINITE⁩/ ⁨Aggregation⁩/Paper⁩/Aggregation_21082019"
    This later causes problems when I later refer to my path using other commands, such as import excel, as STATA tells me that it cannot find the specified file:
    I specify my command like this:
    Code:
    import excel "$path/TOTAL WITH PROPERTYLESS/Germany_total_1400.xlsx", firstrow
    and then STATA returns the command like this, with additional spaces in the command window with an error message "not found":
    Code:
    file /Users/felix ⁩/Dropbox ⁩/Felix⁩/F&Vs PHD ⁩⁩/ ⁨EINITE⁩/ ⁨Aggregation⁩/Paper⁩/Aggregation_21082019/TOTAL WITH PROPERTYLESS/Germany_total_1400.xlsx
    So sum up, the problem seems to be that STATA adds spaces to my command that are not included in the folder names and this seems to misspecify the path when I try to draw on it. I checked spelling and everything is in double-quotes.

    Many thanks in advance for your help.


  • #2
    I cannot replicate your problem on my own setup (which is Windows 7 and Stata version 16). But here are a couple of thoughts:

    1. Are you certain that between the time you define global macro path and the time you use it, no code has modified global macro path?

    2. The answer to the question posed in 1 is no, you don't know for sure. That's because global macros can be accessed and modified by code that is running in other programs and you won't even know it happened until you get wrong results somewhere later that are hard to figure out. Local macros do not have this undesirable, dangerous feature--so things like path names to be used are better stored in local macros which cannot be changed by code that you do not see. I also think that path is a particularly treacherous name for a global macro--it is the kind of thing that some carelessly written program might use for its own purposes. So, in the unlikely event there is some really good reason to use a global rather than a local macro for this purpose, at least pick a name that nobody else is likely to have used--something more like a "strong password."

    Comment


    • #3
      I think your problem involves Unicode support by Stata, but I cannot be certain. When I copy the text from your second code block above and hex dump it, there are instances of "non-printing" Unicode characters following the unwanted spaces. But I can't be sure they weren't somehow changed as part of the process of posting to Statalist.

      How did you create the global command? Was it typed directly into the Do-file Editor? Or was it perhaps copied-and-pasted from somewhere else, or in true Mac fashion (I'm a Mac user) dragged and dropped from a Finder window?

      I suggest you create a new do-file containing just
      Code:
      global path "/Users/felix/Dropbox⁩/Felix⁩/F&Vs PHD⁩/EINITE⁩/Aggregation⁩/Paper⁩/Aggregation_21082019⁩/"
      macro list path
      and do it by typing the commands in directly - no copy/paste or drag and drop. The macro list command will report exactly what is stored in the global macro. If there's no evidence of the spaces in the output shown in the Results window, you've likely solved the problem. Delete the existing global command from the do-file it is in and copy-and-paste the new one into that do-file.

      Comment


      • #4
        Thank you so much for your help Clyde Schechter and William Lisowski. In fact, copying the path from the "Get info" function of the Mac (although adapting it) seems to have caused the problem. It work now!!! Again, thank you so much.

        Comment


        • #5
          Thank you for confirming the solution. Using the macOS Get Info window as you did, I have been able to reproduce your problem.

          When you copy the Get Info path and paste it into the Do-file editor, you get something that looks like what you see in Get Info.
          Code:
          Macintosh HD⁩ ▸ ⁨Users⁩ ▸ ⁨lisowskiw⁩ ▸ ⁨Research
          But in fact there is an invisible character at the end of each sequence "⁩ ▸ ⁨" and when you delete the sequence and replace it with a slash, it's easy to leave the invisible character behind.

          What I found works is to place the cursor after the first character of the next word (for example, between the "U" and "s" in "Users"), then hit the left-arrow key once to move the cursor to just before the first character of the word (which will be just after the invisible character) and then hit the delete key 4 times, and then type a slash. The first time you hit delete, the cursor will appear to not move, Congratulations - that deleted the invisible character. The next three deletes take care of the characters you can see.

          But here's an easier way. When you have a Finder window open to the file or directory whose path you want, Instead of using macOS Get Info, drag the file or directory from your Finder window into the Do-file editor window you are editing in. A popup menu will appear with a number of options; select "Insert Absolute Path", and you will have the path - complete with slashes - inserted into your Do-file as if you had typed it by hand.

          This is a macOS shortcut not specific to Stata; it works with other apps that support it.

          Comment


          • #6
            Dear William, this is a great solution to the time-consuming problem of tying paths from Mac by hand. I tried it and it is fantastic. Thank you so much!

            Comment

            Working...
            X