Announcement

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

  • Mac and Windows path

    Hi,

    I am running stata on both mac (on my personal computer and on windows- office computer). Every time i run the code, i need to change the file paths. I was wondering whether there is a simple step that I could define at the beginning without changing the file paths.

    for example: I run on the main directory (main folder) and I have subfolders (globals) for graphs, regressions, dofiles, and datasets. In my code, I refer to these folders from the main directory. for example save $statadata\dataset.dta. etc. Since the path uses backslashes in mac is there a way around so that i don't need to change these?

    Many Thanks
    Danula

  • #2
    Since the path uses backslashes in mac is there a way around so that i don't need to change these?
    Stata will allow you to use the forward slash character in path names on any operating system, and when run on Windows, Stata will take care of doing what must be done to appease Windows. So just use forward slashes in all path names.

    Comment


    • #3
      Also, you can use the -creturn- value for the OS to set your globals in the filepaths, so I generally use a set up like this:

      Code:
      if `"`c(os)'"' == "MacOSX"   global   stem   `"/users/`c(username)'/data//"'
      if `"`c(os)'"' == "Windows"   global   stem   `"C:/`c(username)'/data//"'
      
      global raw  `"${stem}/project/raw/"'
      global final  `"${stem}/project/final/"'
      **
      u `"${raw}/mydata.dta"', clear
       **do things**
      sa `"${final}/mydata_processed.dta"', replace
      
      ....
      and this helps update all the filepaths in my do-files accordingly.
      Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

      Comment


      • #4
        Thank you both!

        Comment


        • #5
          Originally posted by William Lisowski View Post

          Stata will allow you to use the forward slash character in path names on any operating system, and when run on Windows, Stata will take care of doing what must be done to appease Windows. So just use forward slashes in all path names.
          William, I don't think that Stata has to do anything. I'm fairly certain that Windows, and DOS before it, have always accepted either type of slash in file paths. (I suspect there is some code that converts forward slash to backward slash at the OS level.) From observing students and colleagues who use Macs, I conclude that the Mac OS, on the other hand, is completely unforgiving about the direction of the slashes. As a Windoze user who frequently hears (from Mac-using colleagues) about the vast superiority of Macs, I cling to this one instance in which the Windows OS seems a little more intelligent.
          --
          Bruce Weaver
          Email: [email protected]
          Version: Stata/MP 18.5 (Windows)

          Comment


          • #6
            I havent researched this closely, but at least since the late 60s the computing world has used forward slashes. When DOS (and later Windows OS) came along in the 80s and started using backslashes in filepaths because it had already allocated forward slashes for command line switches (e.g., C:\data\ /w /a) and didnt want to redo things. When HTTP and other online protocols emerged they also used the *nix, etc approach of forward slashes. Later (in the early 90s?) Windows relented & switched to allowing forward slashes as well. I'm not sure if this legacy support for \ counts as any system being more intelligent or not (any more than some programming languages being case sensitive or allowing 4 and 5 space tab characters being an indicator that they are more intelligent), but it certainly trips up users . I find it's better to use forward slashes in all circumstances to help with moving across OSs.

            Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

            Comment


            • #7
              I encountered an issue with directory settings in Stata, where my commands required saving files and temporary files to continue. Both temporary files and actual .dta files were affected by the same problem. Thankfully, a post and response from Professor "eric_a_booth" offered a solution that helped me resolve this frustrating issue. Thank you for your kindness.

              Comment


              • #8
                I suspect the issue above was a backslash acting as an escape character before a macro. There's a Stata FAQ article regarding this behavior:

                https://www.stata.com/support/faqs/p...es-and-macros/

                Comment

                Working...
                X