Announcement

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

  • Error r(601): Do-file cannot find dataset

    Dear all,

    I have been writing my first do-files in Stata and frequently occur the error that the file cannot be found when executing the do-file:

    Code:
    use "Data3.dta", clear
    file Data3.dta not found
    r(601);
    end of do-file
    My folder structure is as follows:
    \ProjectName
    ...\A
    ...\B
    ...\Work
    ........\-To Do
    ................\2018-08-18-ImportClean
    ................\2018-08-19-Match
    ................\2018-08-20-CodeVar

    I set the folder "ProjectName" as working directory.
    In the do-file, I am using .dta files from two different sub-folders "2018-08-19-Match" and "2018-08-20-CodeVar" (this seems to be the problem).

    How can I circumvent this problem so that Stata can find the files by name (without including the entire path to the file)?

    Many thanks in advance for your help!

  • #2
    Well, Stata can't read your mind about which directory you have put which file in. There is no way to avoid providing the pathname along with the filename if you are working with files in different directories.

    Now, you can make it a bit less typographically difficult. You can do something like this:

    Code:
    local folder1 \ProjectName\A\B\Work\-To Do\2018-08-18-ImportClean
    local folder2 \ProjectName\A\B\Work\-To Do\2018-08-18-CodeVar
    
    use `folder1'\Data3.dta
    //    DO STUFF WITH Data3
    
    use `folder2'\Some_other_file.dta
    //   DO STUFF WITH Some_other_file
    
    //  USE ANOTHER FOLDER FROM ImportClean
    use `folder1'\Data5.dta
    //  DO STUFF WITH Data5
    
    // ETC.
    This way you only have to spell out the pathname in full once.

    By the way, you would be better off using / instead of \ as the separator in pathnames, even in Windows. All Stata's file-handling commands know to convert / to \ when passing filenames to Windows. The advantages of using / are (1) you avoid the problems that can arise when you want part of the path or filename to be a local macro (\ doesn't play well with `), and (2) potentially improved portability of code to non-Windows environments.

    Comment

    Working...
    X