Announcement

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

  • Stata and Dropbox on multiple computers - Directory issues

    Hi, we use Stata and Dropbox to collaborate.

    Problem: In our do-files, we always have to adjust the Working Direcotry to our local computers.
    cd "C:\Users\User1\Dropbox\data.dta"
    cd "C:\Users\User2\Dropbox\data.dta"
    cd "C:\Users\User3\Dropbox\data.dta"


    For Mac it is possibe to just write
    cd "~\Dropbox\data.dta"
    and you are fine on all computers.

    On PCs, however, it doesn't work. It says "
    unable to change to ~/Dropbox/".

    Do you have a way to use kind of directory logic on Macs on PCs as well?

    Thanks,
    Fabian


  • #2
    Having faced a similar issue, I've decided that it isn't worth trying to manage this within do files. Here is an extract from the procedures document for my research group. Perhaps you'll find it useful.
    1. Write do files on the assumption that the working directory has already been set to the Modeling directory. So, we can write use workingData on the assumption that we are already in the Modeling directory.
    2. If you need to refer to another directory, do it through a relative reference. So, to import raw data, you could do either
    cd ../Data
    insheet using rawData.csvcd ../Modeling
    or, more compactly
    insheet using ../Data/rawData.csv

    Two things to note here. First, if you use forward slashes (/), Stata will au- tomagically make things work whether your operating system natively prefers forward- or backward-slashed. Second, the double dots “..” simply refer to one directory up in the hierarchy.
    3. Before running the do file, be sure that you’ve set the working directory to the Modeling folder within Stata. You can do that through cd




    (change directory), the “Set working directory” option in the File menu, or through the add-on command fastcd, if you like shortcuts.




    _______________________________________

    Glenn Hoetker
    Professor in Business Strategy

    Melbourne Business School, University of Melbourne
    200 Leicester Street, Carlton, Victoria 3053, Australia
    Email: [email protected]

    I acknowledge the Traditional Owners of the land on which I work, the Wurundjeri people of the Kulin Nations, and pay my respects to their Elders, past and present.

    Comment


    • #3
      If you don't have too many people to share with you can use the capture prefix command with your directory commands. The capture command executes the command that follows it but traps the output including any error messages. Normally you would probably want an error to stop your program at the error point. This command changes that behavior and allows the program to keep running even if a command generates an error.

      In you case, the following might work and included be included in your do file:
      Code:
      capture cd "C:\Users\User1\Dropbox\data.dta"
      capture cd "C:\Users\User2\Dropbox\data.dta"
      capture cd "C:\Users\User3\Dropbox\data.dta"
      capture cd "~\Dropbox\data.dta"
      Best,
      Alan

      Comment


      • #4
        If you can avoid using dropbox, do. It's nifty when it works, but when your data gets corrupted, well.. not so nifty..

        Comment


        • #5
          Any of the following usually delivers the same results:
          Code:
          display "`:environment HOMEDRIVE'`:environment HOMEPATH'"
          display "`:environment USERPROFILE'"
          and you will find tons of other useful material pre-defined for you by the system.
          http://ss64.com/nt/syntax-variables.html

          However, I don't quite understand why you even need this. The commonly developed program should be abstract from the particular user folders and directory structures, and should be guided by external settings. The easiest would be to determine an environmental variable yourself for a particular project (if the project is more like an automated job/batch file) or request it from the user (if the program is more interactive).

          Depending on the situation you may also want to opt for committing the data into the same storage, or writing an external test files, that would be specific to the machine, but the program commonly developed - remain common.

          http://superuser.com/questions/33287...lde-in-windows

          Many other things depend on what is the nature of the differences. Is it different data files for different users, or are the same files placed in different locations?
          You can consider defining symbolic links or the whole new virtual drive with the subst command.

          Best, Sergiy Radyakin

          Comment


          • #6
            If you are all working under windows environment, then this should solve your problem:
            Code:
            cd "C:\Users\\`=c(username)'\Dropbox\..."
            use data.dta
            with this code the username is unique for every user in the different computers and Stata recognzie the local macro without changing it every time (e.g, user1 aaabbb user3afg), but the directory is the same for all the users. This way, all users can use the same do file.

            Comment


            • #7
              Hi, a little delayed but nevertheless thankful response to your comments: Thank you! I actually created a nice solution based on your suggestions:

              I simply code now:
              clear
              cd "`:environment USERPROFILE'\Dropbox\ bla bla bla"
              set more off
              This works on all computers now.

              Also, I didn't know about the ".." for the upper directory. Very helpful.

              Comment


              • #8
                Hi, the OP has been answered but just in case others need the tip, I think another workaround for this might be placing a "profile.do" file in your "My documents" (or equivalent) folder, with the correct cd "C:\Users\User1\Dropbox" (or whichever folder) command. This changes Stata's starting default cd. It is a little unsatisfactory though, as one is often working on several projects at once.

                Comment


                • #9
                  Hi Fabian, good to know you found a solution. I am interested if you've stress-tested it? ie, having all the users making edits to .do files and saving changes concurrently? If you have time and energy, it might be quite useful for many of us on the list. thanks!
                  __________________________________________________ __
                  Assistant Professor, Department of Biostatistics and Epidemiology
                  School of Public Health and Health Sciences
                  University of Massachusetts- Amherst

                  Comment


                  • #10
                    Hi Andrew, a little delayed but here is my answer: We have not encountered any problems so far. Every user made changes in the do-file and if these files were not opened by another user at the same time, no problem occured. However, as with any file in Dropbox, if >1 user has opened the do-file, changes sth. and saves it, then a conflicting file is created by Dropbox.

                    So basically: It works as long as only one person at a time opens the do-file. But the problem that we work on mulitple machines with different directories but the same do-files was solved!

                    Comment


                    • #11
                      Hi Fabian, thanks for the info!
                      __________________________________________________ __
                      Assistant Professor, Department of Biostatistics and Epidemiology
                      School of Public Health and Health Sciences
                      University of Massachusetts- Amherst

                      Comment


                      • #12
                        Hello,

                        Can I use a dataset in Stata right from my Dropbox account which is not synced to my computer?


                        I have always synced my Dropbox data folder to my computer and run “cd /Users/JohnDavis/Dropbox/dataset.dta” to use the dataset I need. However, now I do not have enough space on my computer, so syncing the Dropbox files to my computer is no longer an option (because, in this case, the synced dataset significantly decreases the amount of storage on my computer). When I try to use the file dataset.dta from my unsynced Dropbox account, Stata says "unable to change to /Users/JohnDavis/Dropbox/dataset.dta". The same happens if I use the file dataset.dta from an external hard drive.


                        So, what can I do?


                        Thank you!
                        Last edited by John Davis; 24 Feb 2019, 13:34.

                        Comment


                        • #13
                          Hi Johh,

                          If you haven't already figured this out:
                          I also work with constrained space for large files. For an unsynced file, please right click (from Dropbox app) and "Copy Dropbox Link".

                          Then directly read the file in STata from Dropbox link as below:
                          use "https://www.dropbox.com/s/ft9t1ov1lg5pmbv/CrossSection_UseOfProceeds_G-YMFE_R3.tex?dl=1", clear

                          From what I know, only dta files can be directly read like this. Please note, when the link is first generated - it'll have "dl=0" at the end. I manually change it to "dl=1" - prompting it to download the file, actively into Stata (even though it's not "downloaded" into local PC memory).

                          Hope that helps.

                          However, I've not been able to write a dta file into Dropbox web directly, without writing to my local disk first (and then "Smart-syncing" it to "online only"). And of course, the same disk space issues come up here too when it's a large dataset.

                          Comment

                          Working...
                          X