Announcement

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

  • Unable to read .dta file through do file - works fine otherwise

    Hello!

    I am working on a do file alongside a colleague but its commands will not load successfully and it generates an r(601) error. The code stops at the point where I instruct which file to load and it says

    'file /some_data.dta' not found

    However, when I type

    use 'file/some_data.dta'

    into the command box, it loads fine. This tells me it must be something wrong with the code in the do file itself and not the filepath I am using because it loads that loads into Stata fine. I am a MacOS user working with Stata15. Because my colleagues work on Windows, I needed to change the filenames (done to my understanding below).

    Here is the code I am working with:

    ----------------------------------------

    gl filepath =‎⁨"/Users/josephkalarickal/Desktop/Google Drive/Research Assistant/Work for the Professor/Work Projects/Ongoing Projects/SkillsCountry/"
    gl data ="$filepath/data"
    gl dofiles ="$filepath/dofiles"
    gl tempfiles ="$filepath/tempfiles"
    gl results ="$filepath/results"
    gl logfiles ="$filepath/logfiles"

    use "$filepath/some_data.dta", clear *this is where the code breaks for some reason.

    ----------------------------------------

    Thank you in advance for the help.

    Joseph


  • #2
    The filepath global declaration has a ‘/‘ at the end, so when expanded in your -use- call, you get 2 ‘/‘ in a row => error. [?] You could check this with -set trace on-

    Comment


    • #3
      Stephen is most likely correct pointing out the 2 / .

      Maybe it is because you are using Google Drive, but wouldn't it be easier to just set the working directory in Stata at the beginning of the do file (i.e., File -> Change working directory)? Then all you need to do is type use 'file/some_data.dta', which you said you have done and works. This always works for me.

      Comment


      • #4
        And following up Chris in #3: note too that do-files can have several -capture cd ...- lines at the top of them, with different lines corresponding to the file directory set-ups for different users

        While we're here on this sort of topic, I strongly recommend checking out -fastcd- on SSC. Particularly useful for interactive work, especially when combined with -dirtools- (SSC)

        Comment

        Working...
        X