Announcement

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

  • Command "do" does not work although working directory is specified

    Dear Statalist Users,

    I am trying to run multiple do files in a row by using the command "do" (filename).
    My current working directory according to the
    Code:
    pwd
    command is the following
    Code:
    E:\Stata\Masterarbeit\Datenarbeit&Analyse\Do-Files
    Next, I specified a global for Stata where to access the folder with my do-files stored:
    Code:
    global source "E:\Stata\Masterarbeit"
    Another global specifies where Stata can access the Do-Files:
    Code:
    global do_path "$source\Datenarbeit&Analyse\Do_Files"
    Lastly I tell Stata to run the do-files in the folder "Do-Files" with the following command
    Code:
    do "$do_path/01_Merging_Cleaning_Summary_Statistics.do"
    However, stata gives me the following error message:
    Code:
    file E:\Stata\Masterarbeit\Datenarbeit&Analyse\Do_Files/01_Merging_Cleaning_Summary_Statistics.do not found
    Can someone tell me why this is happening? I really don“t understand it since the working directory looks correctly specified to me.

    I am using Stata Version 16.1

    If you have any further questions, please let me know and I will try to be more precise.

    Thank you very much in advance!
    Last edited by Hubertus Meien; 25 Mar 2021, 09:39.

  • #2
    Hi Hubertus,

    Have you tried changing the direction of the slash?:
    Code:
     
     do "$do_path\01_Merging_Cleaning_Summary_Statistics.do"
    best,
    Rhys

    Comment


    • #3
      Hard to say. Maybe a typo in the file name? It is pretty long, so typos can happen. I would start with the following commands:
      Code:
       cd "E:\Stata\Masterarbeit\Datenarbeit&Analyse\Do_Files/"
      dir
      The first command will check if the directory exists (and move there). The second command will list all files in that directory. Look for the .do file and check letter for letter the name of the .do file.
      Last edited by Maarten Buis; 25 Mar 2021, 09:46.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Hi Rhys,

        thank you for your quick response! Yes I have tried that. It still gives me the same error message though:

        Code:
        do "$do_path\01_Merging_Cleaning_Summary_Statistics.do"
        Code:
        file E:\Stata\Masterarbeit_Hubertus_von_Meien\Datenarbeit&Analyse\Do_Files\01_Merging_Cleaning_Summary_Statistics.do not found

        Comment


        • #5
          Hubertus,

          In your code, you switch between back and forward slashes on the line
          Code:
          do "$do_path/01_Merging_Cleaning_Summary_Statistics.do"
          That may be the source of the issue. Either switch the "/" to a "" for consistency with your computer's filesystem, or move all "" to "/", as Stata is able to translate "/" as needed to "" on Windows systems. So, either
          Code:
          pwd
          global source "E:\Stata\Masterarbeit"
          global do_path "$source\Datenarbeit&Analyse\Do_Files"
          do "$do_path\01_Merging_Cleaning_Summary_Statistics.do"
          or

          Code:
          pwd
          global source "E:/Stata/Masterarbeit"
          global do_path "$source/Datenarbeit&Analyse/Do_Files"
          do "$do_path/01_Merging_Cleaning_Summary_Statistics.do"
          Should work. Hope that helps!

          Jamie

          Comment


          • #6
            I solved it. In the end it was a typo error. Thank you very much for your quick responses!

            Comment


            • #7
              Stata's generous about the difference between forward and backward slashes.

              The only exception is a backward slash before a local macro reference, which will usually bite you.

              Comment

              Working...
              X