Announcement

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

  • An error with pwd and log using command

    Hi STATAlisters!

    The problem that I have is 2 pronged. I am trying to change my current working directory with the cd command like so:
    Code:
    cd "/Users/npisharody/Documents/Research"
    It runs without an issue. But when I try to check what directory I am working in using the pwd command, it returns the following line
    Code:
    macOS refuses to provide that information
    I am really not sure what I am doing wrong or if there are any access settings I need to tweak.

    The second problem I have is that after changing the directory, I am writing the following code:
    Code:
    capture mkdir "/Log Files"
    log using "/Log Files/graphs.log", replace
    And it returns:
    Code:
    file /Log Files/graphs.log could not be opened
    I have used these commands so many times - and I do not see what the issue is. The rest of the do file is still empty as I am just starting a new code.

    Thanks in advance,
    Nilima

    EDIT: The following line works:
    Code:
    log using "~/Documents/Research/Log Files/graphs.log", replace
    There seems to be an error with my referencing that folder. I do not want to be writing the entire path every time I have to open a file or a log or a dataset. It will not only be time-consuming but also be a reading nightmare for the professors I will be sharing my code with. Any help is appreciated.
    Last edited by Nilima Pisharody; 08 Oct 2020, 10:38.

  • #2
    Looks like a permission issue, although it is strange (assuming you're logged in as npisharody). Check the following link and see if this resolves the issue:
    https://www.stata.com/support/faqs/m...-in-directory/

    Can you also check if you have a log file open somewhere? It is possible that the file is "locked" if it has previously been created and the system has not registered it as being closed. A quick system reboot should take care of that if you're still having trouble.

    Comment


    • #3
      Originally posted by Daniel Shin View Post
      Looks like a permission issue, although it is strange (assuming you're logged in as npisharody). Check the following link and see if this resolves the issue:
      https://www.stata.com/support/faqs/m...-in-directory/

      Can you also check if you have a log file open somewhere? It is possible that the file is "locked" if it has previously been created and the system has not registered it as being closed. A quick system reboot should take care of that if you're still having trouble.
      Hi Daniel,

      The permissions are all proper. I checked the link and that didn't really resolve the issue.

      I tried writing
      Code:
      capture log close
      first as well, if in case any other logs are open. It still gives me the same error.

      Comment


      • #4
        The first link was an example, and by the looks of it, not the best example. Try this for the folders in question:
        https://support.apple.com/en-gb/guid.../mchlp1038/mac

        Regarding the log, I don't think Stata has it open, so error capturing the log close command won't do anything. Can you see if the log is present in the folder? You will need to resolve that first, or use a different log name as a temporary workarond.

        Comment


        • #5
          Originally posted by Daniel Shin View Post
          The first link was an example, and by the looks of it, not the best example. Try this for the folders in question:
          https://support.apple.com/en-gb/guid.../mchlp1038/mac

          Regarding the log, I don't think Stata has it open, so error capturing the log close command won't do anything. Can you see if the log is present in the folder? You will need to resolve that first, or use a different log name as a temporary workarond.
          I checked the permissions. Once again. Rebooted the system. They are all fine. It's still not letting me view the working directory.
          The log one - I am not sure what to still. As I said I have used these basic commands so many times - It seems very weird that this is happening now.

          Comment


          • #6
            Have you recently upgraded your OS or Stata? I wonder if reinstalling Stata will reset your software permissions with the operating system (you may get a prompt for allowing access). And you an access your folders through Finder or through Terminal, yes?

            Comment


            • #7
              On macOS or Linux starting a file or directory path with a "/" means it is relative to the root directory "/" rather than to the current directory you are working in. You should replace
              Code:
              capture mkdir "/Log Files"
              log using "/Log Files/graphs.log", replace
              with
              Code:
              capture mkdir "Log Files"
              log using "Log Files/graphs.log", replace
              I cannot explain the failure of pwd. What version of Stata are you using?
              Code:
              . about
              
              Stata/SE 16.1 for Mac (64-bit Intel)
              Revision 17 Sep 2020
              Copyright 1985-2019 StataCorp LLC

              Comment


              • #8
                William Lisowski
                I am on: Stata/MP 16.1

                Code:
                cd "/Users/npisharody/Documents/Research/"
                
                /// Make Folders ///
                capture mkdir "Data"
                capture mkdir "Log Files"
                capture mkdir "Do Files"
                  
                log using "Log Files/graphs.log", replace
                capture log close
                still gives me the same error

                Comment


                • #9
                  Delete the three subdirectories in question (or move them out of the Research Folder temporarily, or change their names), and try this code. Copy all the commands and output from your Results window and paste that into a CODE block.

                  Code:
                  cd "/Users/npisharody/Documents/Research/"
                  capture noisily pwd
                  shell pwd
                  shell ls -la
                  /// Make Folders ///
                  capture noisily mkdir "Data"
                  capture noisily mkdir "Log Files"
                  capture noisily mkdir "Do Files"
                  shell ls -la
                  
                  log using "Log Files/graphs.log", replace
                  shell ls -la
                  log close
                  type "Log Files/graphs.log"

                  Comment


                  • #10
                    I upgraded to Stata 18 recently and ran into the same issue. Any solution found? Thanks a bunch!

                    Comment


                    • #11
                      I found the answer. It seems my Mac does not grant Stata the access to my Documents folder. This link discusses the steps to enable the access: https://support.apple.com/en-gb/guid...hld5a35146/mac.
                      OS: MacOS 13. Stata Version: Stata 18 MP

                      Comment


                      • #12
                        In case someone ends up on this issue.

                        After trying to manage data files in my working directory located in OneDrive, I also encountered the error message:

                        Code:
                        macOS refuses to provide that information
                        Recently, I updated my macOS software to Sonoma 14.5. After the update, permissions to access files and folders from different applications (Stata included) changed.

                        Following the steps in this link solved the issue (also posted in #11 above).

                        OS: macOS 14.5
                        Stata 17 MP

                        Comment

                        Working...
                        X