Announcement

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

  • Stata 17 problem (not in 16): exporting to long paths

    In Stata 16, I could export results and data to a file regardless of the length of the path name. However, in Stata 17, there appears to be a limit such that if the path name is over about 80 characters long, I get an error. For example in the code below, if substitute path with a path on my hard drive that is more than 80 characters long, it fails. This is an esttab example, but I have the same problem with export delimited, so it seems like a general problem.
    Code:
    . sysuse auto, clear
    . eststo: quietly regress price weight mpg
    . eststo: quietly regress price weight mpg foreign
    . esttab using "path\example.csv"
    ...
    
    file path\example.csv could not be opened
    r(603);

  • #2
    Are you sure that the path is correctly specified? Does it exist and do you have write-access to it? Do you maybe have an old version of that file open (preventing you from overwriting)? I don't think this is a Stata problem, or maybe it's a problem with -esttab-?

    Comment


    • #3
      I'm sure the path is correct because if use 'cd path' I get no error. And I have verified I can write to it with other applications.

      Comment


      • #4
        Is your path to a network location, in the form of "\\server\path\to\file" ? Maybe you could try replace "\" with "//" ? I was able to reproduce the same error with Stata 16 by doing this, so it's odd that something broke when you moved from Stata 16 to 17.

        This still seems like an issue with -esttab- because official Stata commands seems perfectly able to use short and long paths, networked or local for me. For example, can you use -use- or -save- or -export delimited- with your path that causes a problem?

        Comment


        • #5
          It's clear that the code you show in post #1 is invented, since "path\example.csv" is shorter than 80 characters and thus doesn't demonstrate the problem you report.

          Lacking evidence, I share the skepticism expressed by Leonardo in post #2, as will many others here. What you should do is create a simple example that actually demonstrates the problem, run the example, and in Stata's Results window, copy the commands and their output from the Results window and paste it into CODE block for us to see.

          Here's an example run on Stata 16.1 with a path in excess of 80 characters that - as expected, because the problem is new to Stata 17 - does not demonstrate the problem.
          Code:
          sysuse auto, clear
          save "/Users/lisowskiw/Downloads/A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/autos", replace
          Code:
          . sysuse auto, clear
          (1978 Automobile Data)
          
          . save "/Users/lisowskiw/Downloads/A1234567890123456789012345678901234567890/B123456789012345678
          > 9012345678901234567890/autos", replace
          (note: file /Users/lisowskiw/Downloads/A1234567890123456789012345678901234567890/B12345678901234
          > 56789012345678901234567890/autos.dta not found)
          file /Users/lisowskiw/Downloads/A1234567890123456789012345678901234567890/B123456789012345678901
          > 2345678901234567890/autos.dta saved

          Comment


          • #6
            I used 'path' as a stand in because I didn't want to disclose the names of folders on my hard drive. If I did disclose those folder, it probably wouldn't help because no one would be able to reproduce the problem unless they had the same drive structure. However, if you have Stata 17, you can substitute any long path you want.

            The path is not on a network location. And I get this error with -export delimited- so it's definitely not an esttab issue.

            I'm using code that was working fine in Stata 16.1. I'm just re-running that code in Stata 17 now and getting errors.

            Comment


            • #7
              Upon looking at this in more detail, I had realize I had a slash instead of a backslash at one place. It looks like Stata 16.1 was forgiving but Stata 17 is not. Now that I fixed it, it is fine.

              Comment


              • #8

                Stata is supposed to work equally well with forward slashes in paths - and using forward slashes instead of backslashes can help avoid problems when constructing a path name that includes a local macro. So if a forward slash "/" fails where a backslash "" succeeds, I'm concerned that you have indeed discovered a bug - just not the bug you thought.

                Here is how to avoid disclosing folder names on your hard drive other than the ones created for the demonstration. First cd to a directory in which you have previously created the hierarchy of folders

                A1234567890123456789012345678901234567890 containing B1234567890123456789012345678901234567890 containing C1234567890123456789012345678901234567890

                and then run the sample code, which does not disclose any other folder names.
                Code:
                . sysuse auto, clear
                (1978 Automobile Data)
                
                . save "./A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos", replace
                file ./A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta saved
                I'd appreciate it if you could try this as is, with forward slashes. If it fails in Stata 17 for Windows it would qualify as a bug. If instead it works, then there must be something else about your actual code that is causing problems. As a Mac user, I can't use backslashes in file paths. In the past, I have seen Windows code on Statalist with a mixture of backslashes and forward slashes, so having just one forward slash should not be a problem.

                Comment


                • #9
                  Some more food for thought while debugging.

                  Code:
                  . sysuse auto
                  
                  . // #1 through #4: These all work. Note the use of forwards or backwards slashes, absolute paths or relative paths.
                  . save "C:\tmp\A1234567890123456789012345678901234567890\B1234567890123456789012345678901234567890\C1234567890123456789012345678901234567890\autos.dta", replace
                  (file C:\tmp\A1234567890123456789012345678901234567890\B1234567890123456789012345678901234567890\C1234567890123456789012345678901234567890\autos.dta not found)
                  file C:\tmp\A1234567890123456789012345678901234567890\B1234567890123456789012345678901234567890\C1234567890123456789012345678901234567890\autos.dta saved
                  
                  . save "C:/tmp/A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta", replace
                  file C:/tmp/A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta saved
                  
                  . cd "C:\tmp"
                  . save "./A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta", replace
                  file ./A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta saved
                  
                  . save ".\A1234567890123456789012345678901234567890\B1234567890123456789012345678901234567890\C1234567890123456789012345678901234567890\autos.dta", replace
                  file .\A1234567890123456789012345678901234567890\B1234567890123456789012345678901234567890\C1234567890123456789012345678901234567890\autos.dta saved
                  
                  // What about with macro substitution?
                  . local path1 "A1234567890123456789012345678901234567890"
                  . local path2 "B1234567890123456789012345678901234567890"
                  . local path3 "C1234567890123456789012345678901234567890"
                  
                  . // #5: This works
                  . save "./`path1'/`path2'/`path3'/autos.dta", replace
                  file ./A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta saved
                  
                  . // #6: This also works
                  . save "`path1'/`path2'/`path3'/autos.dta", replace
                  file A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta saved
                  
                  . // #7: This doesn't work because the path is invalid.
                  . cap noi save "/`path1'/`path2'/`path3'/autos.dta", replace
                  (file /A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta not found)
                  file /A1234567890123456789012345678901234567890/B1234567890123456789012345678901234567890/C1234567890123456789012345678901234567890/autos.dta could not be opened
                  
                  . // #8: This doesn't work because I escaped the single quote, bypassing the macro substitution.
                  . cap noi save ".\`path1'\`path2'\`path3'/autos.dta", replace
                  (file .`path1'`path2'`path3'/autos.dta not found)
                  file .`path1'`path2'`path3'/autos.dta could not be opened
                  It's possible based on the similar error message that you might have rubbed up against an error of type #7 or #8, but it might be worthwhile to check for those subtleties. This was run on Stata 17 on Windows. Precisely the same code yielded the same results with Stata 16.1.

                  Comment


                  • #10
                    Thanks Leonardo and William. The above code doesn't produce errors. Maybe the issues is that if I have a folder nested seven layers deep and each layer has a folder name of about 15 characters, the error pops up. Overall, I can just report that a bit of code that worked in Stata 16 didn't work in Stata 17. I removed Stata 16 so I can't do any comparison testing any more.

                    Comment


                    • #11
                      Sorry, Chris. I'm not sure what went wrong but I don't think Stata (per se) is to blame. It's possible you might have found some small bug in a package or code.

                      Here's a test in a directory structure 10 levels deep, with nine directories having names 21-characters long.

                      Code:
                      local path "c:/tmp"
                      foreach d in A B C D E F G H I {
                          local path "`path'/`d'12345678901234567890\"
                          cap mkdir "`path'"
                      }
                      
                      sysuse auto
                      
                      local fpath "C:\tmp\A12345678901234567890\B12345678901234567890\C12345678901234567890\D12345678901234567890\E12345678901234567890\F12345678901234567890\G12345678901234567890\H12345678901234567890\I12345678901234567890"
                      
                      save "`fpath'/autos.dta", replace

                      Comment


                      • #12
                        Post Removed
                        Last edited by Sandipta Chakraborty; 07 Oct 2021, 13:23.

                        Comment


                        • #13
                          Hi Sandipta, please do not spam the forum with multiple posts for the same question. You have already started a thread here, so see there for any further discussion.

                          Comment


                          • #14
                            Not sure if this was your problem, but apparently Windows can impose a maximum file path length: https://learn.microsoft.com/en-us/wi...?tabs=registry.

                            Comment

                            Working...
                            X