Announcement

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

  • Problem with capture confirm file

    I have a folder containing some 70,000 systematically named files which I am going to merge into fewer files eventually. I start with running a simple loop using the capture confirm file construct to check which files do not exist but I always receive code 601 (not found) even for the files I can see that exist. Can anyone think of a reason why this happens?

    foreach t in 17928 17956 17987 18017{
    foreach f in 5560003468 5560004615 5560005331 {
    capture confirm file "C:\Users\Nima\Desktop\Directors\Merged`t'-`f'"
    dis _rc
    use "C:\Users\Nima\Desktop\Directors\Merged`t'-`f'"
    clear
    }
    }

    Just to illustrate the problem, I have added a shortened version of the loop I am running above. All 12 files do exist above and Stata opens them one by one in the loop but first displays code 601.












  • #2
    Replace all backslashes \ with simple slashes /. See Cox (2008) for an explanation.

    Best
    Daniel

    Cox, N. 2008. Stata tip 65: Beware the backstabbing backslash. The Stata Journal, 8(3): pp. 446--447.

    Comment


    • #3
      Thanks for your suggestion Daniel, I tried that to no success. First of all, nowhere in the loop the macros are coming immediately after backslashes so using backslashes is not problematic. Second of all, in the illustrative loop I have included, Stata is able to open the file names referred to, but it is not able to verify they exist

      Best
      Nima

      Comment


      • #4
        Whoops, my advice was based on a too short and quick look -- sorry. Having had a closer look, I believe the problem is that the file extension, .dta, is missing. The use command, is designed to open Stata datasets and is clever enough to add the default file extension. The confirm command, which is supposed to confirm the existence of any type of file, does not add a default file extension and requires that file extension be mentioned explicitly. Type

        Code:
        capture confirm file "C:\Users\Nima\Desktop\Directors\Merged`t'-`f'.dta"
        That should fix the problem.

        Best
        Daniel

        Comment


        • #5
          Thanks Daniel, that is exactly where the problem lies... very helpful.

          Best
          Nima

          Comment

          Working...
          X