Announcement

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

  • Main directory Mac OS

    Hi,

    I am currently using Mac OS X stata, and I have some problems setting the main directory.

    I am sharing the do files with my team and all the others use PC.

    The global directory command is:

    else if "`c(username)'"=="eddie"{
    global maindir1 "/Users/Eddie/Desktop/Project/Data"
    global maindir2 "/Users/Eddie/Desktop/Project/Data"


    and later on I would like to use the data from this directory:

    capture use "$maindir1/__.dta",clear

    I have the problem using the main directory.

    Thank you for the help!

  • #2
    I would remove the capture from the use command and see what the error message is that the capture is causing to not be displayed.

    I am assuming you have a folder on your Desktop named Project containing a folder named Data containing a dataset named
    Code:
    __.dta
    or else that you replace the two underscore character with the name of an actual dataset in that directory.
    Last edited by William Lisowski; 21 Feb 2020, 19:25.

    Comment


    • #3
      Yes,

      I put capture so that the others can disregard my command for the PC version.

      The __.dta underscore was just the anonymous name for the data.

      I think the problem is with "$maindir1/", where I cannot refer to the main directory.

      ​​​​​​​Thank you very much!

      Comment


      • #4
        You should not be using capture when your program is not running correctly because capture suppresses all error messages and allows the program to continue to run if there is an error.

        To allow others to disregard your command for the PC version you should use quietly . Consider the following examples.
        Code:
        . do "/var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T//SD28139.000000"
        
        . capture use "gnxl.dta"
        
        . describe
        
        Contains data
          obs:             0                          
         vars:             0                          
        Sorted by: 
        
        . // there is no data here but the do-file is continuing to run
        . 
        end of do-file
        Code:
        . do "/var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T//SD28139.000000"
        
        . quietly use "gnxl.dta"
        file gnxl.dta not found
        r(601);
        
        end of do-file
        
        r(601);
        
        .
        Now replace capture with quietly and try again and tell us what the error message is. "I cannot refer to the main directory" does not tell us what Stata thinks the problem is, it tells us what you think the problem is.

        Please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

        The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

        Section 12.1 is particularly pertinent

        12.1 What to say about your commands and your problem

        Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!

        Comment


        • #5
          Thank you very much William!

          It perfectly works with quietly use.

          But if I code:

          Code:
          capture use "$maindir1\Data\xnf.dta"
          quietly use "$maindir1/Data/xnf.dta"
          The first line is for the PC version, and I added a second line for Mac version.

          For the others with the PC version, won't they get an error running the
          Code:
           quietly use "xnf.dta"
          ?
          Last edited by Ed Suh; 23 Feb 2020, 13:10.

          Comment


          • #6
            You do not need two different use commands - the one with the forward slashes
            Code:
            quietly use "$maindir1/Data/xnf.dta"
            will work for both Windows and macOS.

            Stata will allow you to use the forward slash character in path names on any operating system, and Windows will not object. My understanding is that every version of Windows has accepted "/" as a path separator, and every version of MS-DOS beginning with DOS 2.0 (the first version that had subdirectories). Only in command lines was "/" not allowed, because it had already been used as a switch delimiter in MS-DOS 1.0.

            This is discussed, for users of Stata 16 at least, in section 18.3.11 of the Stata User's Guide PDF included with Stata and accessible through Stata's Help menu.

            Comment


            • #7
              Thank you very much!

              My concern is that they might have earlier versions of Stata, but I will try will the second version!

              Comment


              • #8
                My note was misleading - forward slashes have been supported just about forever, but they weren't documented in the User Guide until recently, and if you have an older version of Stata, you might not find a section 18.3.11 of the User's Guide. But what matters is that the quietly use command in post #6 will work with any Stata version your users are likely to have.

                Comment

                Working...
                X