Announcement

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

  • Using Stata with Files Stored on Dropbox from both a Mac and a PC

    Hi,
    I work on both a PC and a Mac, one at home and one at work, and use dropbox to sync my files. I am having trouble finding an easy to run stata do files from both locations, because the file names seem to be handled differently in mac vs. pc. I've read previous posts about changing the directory to dropbox, but I continue to have issues with the actual name of the file, mostly because the slashes are different (\ vs /). For example, here is the command to use a file in my pc from dropbox:

    use "C:\Users\claybav\Box Sync\Consult Study\Analysis Files\master.dta"

    and here is the command to use the same file in my mac:

    use "/Users/claybavinger/Box Sync/Consult Study/Analysis Files/master.dta"

    Is there anyway to easily have the computers call these files the same name, so that I can run .do files from pc and mac?

    Thanks very much!
    Clay Bavinger
    University of Michigan

  • #2
    Stata (in any OS) doesn't care if you use / or \. It will translate accordingly. In fact, / is preferable. See http://www.stata-journal.com/article...article=pr0042.
    You should:

    1. Read the FAQ carefully.

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

    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

    Comment


    • #3
      You can use the pathof ado file to get the left side of the path name.

      Code:
      ssc install pathof
      
      pathof "Consult Study" , local(cstudy)
      display `"Path of "Consult Study" folder: `cstudy'"'
      use "`cstudy'/Analysis Files/master.dta"
      Mike

      Comment


      • #4
        You could also check the operating system using the c-class value c(os) (operating system). You can improve upon this simple, untested example:

        Code:
        if c(os) == "Windows" local mypath "C:/Users/claybav/Box Sync/Consult Study/Analysis Files"
        if c(os) == "MacOSX"  local mypath "/Users/claybavinger/Box Sync/Consult Study/Analysis Files"
        use "`mypath'/master.dta"

        David
        David Radwin
        Senior Researcher, California Competes
        californiacompetes.org
        Pronouns: He/Him

        Comment


        • #5
          I also like the SSC package fastcd for this. If you associate the same code with the right directory on each computer, then your do-file can use c code rather than cd absolute_path.

          Comment


          • #6
            My general advise on questions like this would be:

            (1) Do not use absolute pathes to the dataset. Instead access the data set with relative pathes from the directory in which the do-file is being stored. .
            (2) Allways use / instead of the backslash
            (3) Make the directory in which the do-file is being stored the working directory.
            (4) If absolute pathes cannot be avoided, access them by global macros defined in profile.do

            Respecting these four rules works perfectly well for me to collaborate with others in a cloud environment accessed by Linux, Mac and Windows computers. (ownCloud, not dropbox, but that should not make a difference ..).

            For number 3 -fastcd- and/or -dirtools- can be very helpful. Both are on SSC

            Comment

            Working...
            X