Announcement

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

  • Using the -capture- command when working with different people

    Hello Statalisters,

    I'm trying to understand better how the -capture- command works because I will have to work with colleagues on a university assignment and I would like to make it easier for everyone. I currently tried something on a do-file and I know where the code is wrong, but sadly I do not know how to fix this issue. Let's suppose we're 3, and we all have access to a common Dropbox. I created 3 macros with the same name (dropbox), each storing our different paths to the Dropbox. Now, I thought that the -capture- command would only store my own path but then I realized that Stata has no way to know which path belongs to who!

    Code:

    Code:
    capture global dropbox "C:/Users/Person1/..."
    capture global dropbox "C:/Users/Person2/..."
    capture global dropbox "C:/Users/Person3/..."
    
    cd "$path"
    
    use "$path/file.dta", clear
    Expectedly, I'm Person 1 and Stata answers me that it couldn't find the file of Person 3, because I understood that everytime I create a new global macro named dropbox, the previous one is erased. Rather than only selecting the first line of the do file, and then selecting the rest of the code to run it, I'd like the dofile to run smoothly and the same way for everyone. I'm sure there is a way to do it but I can't seem to find it after many attempts. Can anyone help me better understanding how the capture command works?

    Regards,

    Hugo
    Last edited by Hugo Denis; 04 May 2022, 04:18.

  • #2
    If I am understanding this correctly, this is to me backwards. Indeed you're already explaining that capture can't help each member of your group to make the right decision.

    At the risk of displeasing slightly my friend Clyde Schechter I will say that very, very occasionally I can see a case for using a global and this could be an example.

    The rules could be

    1. Each member of the group must know and set their own global dropbox before working on the data.

    2. Then each member of the group can run a do-file that refers to, but does not set, $dropbox.

    This doesn't sound like a very equal assignment if you're doing most of the Stata thinking!

    Comment


    • #3
      That said, the structure

      capture ...

      if _rc capture ...

      if _rc capture ...

      tries each version in turn, but the assumption is still that only one statement works for each person. My guess is that setting the global is just assigning some text, and the real test is whether that global works when you try to read in the data, in which case I suggest #2 all over again.
      Last edited by Nick Cox; 04 May 2022, 06:12.

      Comment


      • #4
        Dear Nick,

        Thank you for your suggestions. The one provided in #2 is a good idea to get rid of this problem!

        We also looked at

        Code:
        creturn list
        And noticed that each of our "Users" was stored in a c() function. We tried

        Code:
        global dropbox "C:/Users/`=c(username)'/..."
        It worked, but it seems too good to be true. Is there anything wrong with this method?

        No worries, I wrote this topic on behalf of all of us three!

        Regards,

        Comment


        • #5
          Whether your last solution works depends intimately on details of how people access your network and their files and you should be alarmed if I knew what they were... or even knew what it is. It would be good if it did work.

          Comment


          • #6
            I think you are looking for

            Code:
            capture use "C:/Users/Person1/file"
            capture use "C:/Users/Person2/file"
            capture use "C:/Users/Person3/file"
            because the -global- statement will always succeed, while the -use- statement will only succeed if "file" is available in the specified directory. With no -clear- option on the use statement, these -use- statements won't write over each other. Nevertheless, asking the users to put a global assignment in their sysprofile.do is also a good idea.

            I am in the habit of running lots of programs for other users, and as you are recognizing here minimal edit sensitivity is absolutely vital if confusion is to be avoided.

            Comment


            • #7
              I like Daniel's idea in #6. I work with other users too, but they are always responsible for their own files, so I avoid these management burdens.

              Comment

              Working...
              X