Announcement

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

  • stata replaces forwardslash with backslash - why?

    Hi Statalist,

    I've already run the cd command in my file and I know the import is referencing the correct location and filename. What's curiously happening is the third forwardslash is consistently replaced by Stata with a backslash, which stops the run and thus stops my progress.

    . import excel using "/2013/01/2233_20130101_ALL.xls", sh ("REHUAllResults.rpt") firstrow
    file /2013/01\2233_20130101_ALL.xls not found

    As you can see, when I run the import line the response I get shows the third forward slash replaced with a backslash. Can anyone explain to me why this is happening and what I can do to resolve it?
    Last edited by Virginia McFarland; 20 Jun 2014, 08:35.

  • #2
    No clear idea about the backslash. It might have something to do with your operating system (presumably some Windows version). Probably Stata separates the filename specification internally and puts it back together using the Windows character (\).

    Try to either get rid of the first slash or add a dot in front of it indicating the current directory as in

    Code:
    . import excel using "2013/01/2233_20130101_ALL.xls", sh ("REHUAllResults.rpt") firstrow
    or

    Code:
    . import excel using "./2013/01/2233_20130101_ALL.xls", sh ("REHUAllResults.rpt") firstrow
    Best
    Daniel

    Comment


    • #3
      That works, Daniel. Thank you!

      Comment


      • #4
        Virginia,

        It's worth mentioning that Stata considers the forward slash and back slash to be the same thing in this context, so the fact that Stata replaced one with the other is probably not the problem. Stata recommends the forward slash (regardless of operating system conventions) because the back slash has other uses as well.

        I concur with Daniel's suggestions. Unless the "2013" folder is directly under the root directory, you will need to choose one of his suggestions to make the path you specified relative to the current working directory. If this doesn't work, you should provide more information on exactly where the file is stored (i.e., complete path).

        Regards,
        Joe

        Comment


        • #5
          Regardless of forward or backward slashes, the following two mean dramatically different file names:

          Code:
          "2013/01/2233_20130101_ALL.xls"
          "/2013/01/2233_20130101_ALL.xls"
          The first one means literally: "proceed from current directory to 2013 subdirectory, then to 01 subdirectory, and there you will find the file 2233_20130101_all.xls".
          The second one means literally: "proceed to the root directory of the current drive, from there to 2013 subdirectory, then to 01 subdirectory, and there you will find the file 2233_20130101_all.xls".

          No wonder only one of them worked, since the current directory is likely not the drive's root directory.

          Compare also:
          Code:
          dir *.*
          dir \*.*
          Best, Sergiy Radyakin

          Comment

          Working...
          X