Announcement

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

  • Multiple User Stata File in Dropbox

    Dear All,
    I have a question regarding Stata working directory. I am working with multiple people on a project stored in dropbox. The problem is that of course everyone has a different path, so we always have to change in the cd command in the begining. eg.
    Code:
    C:\harveysPC\Dropbox\Project
    C:\MikesPC\Dropbox\Project
    Suppose my code.do file is in Project folder of Dropbox. Ideally, I would like "code.do" to know that it is stored in folder "Project" and then from there on only use subfolders of the folder "Project". For example, say code.do should import data, I would want it to do:

    Code:
    use "Data\dataset.dta"
    where "Data" is a folder in Project, and "dataset.dta" is a dataset in the folder "Data". This way, we would not have to change the cd command every time we run something. I know that this is really easy in Matlab (in fact it is the standard setting). is there a way to do this in Stata?

    Thanks in advance!

    Best,
    Harvey


  • #2
    The approach I would take would be to use a global macro to specify the user's Dropbox directory, and require the user to set the global macro before invoking your code. This could be easily handled by instructing the users in preparing a profile.ado to set that global macro each time they launch Stata.

    I should add that I know of no way of having Stata code know the path to the file it is contained in. I've been down that road myself, for other reasons.

    Comment


    • #3
      Good idea. I just added

      global drp C:\Dropbox

      to profile.do. Then, when I opened Stata, I gave the command

      use $drp\statafiles\glm-logit

      and it worked.

      Note that it is profile.do though, not profile.ado.

      I copy profile.do to different machines -- so what I would further like is to have the dropbox directory auto identified.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        If Dropbox is installed in a standard location like it is in your example you can use macro substitution fairly easily as well:

        Code:
        cd `"C:/`c(username)'/Dropbox/Project/"'
        If users have things installed in different locations it can be a bit difficult, but if you're working in an enterprise environment where IT controls where things can be installed it makes it fairly easy to substitute parts of the file path using system macros.

        Comment


        • #5
          Good advice from wbuchanan above for those in a structured environment (which I am pleased to say I no longer am).

          Let me point out that his use of forward slashes rather than reverse slashes in the path is crucial. Stata will handle forward slashes in Windows, OS X, and Linux environments equally well: it does what is necessary for the environment it finds itself running in. On the other hand, a reverse slash will "escape" interpretation of the character following it, causing special characters like ` or $ to be treated literally, and preventing expansion of the `c(username)' in the path.
          Last edited by William Lisowski; 20 Feb 2016, 10:23.

          Comment

          Working...
          X