Announcement

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

  • Unique Sharepoint and OneDrive references and sharing files using "cd" command ("global" command a solution?)

    Good afternoon,

    In our team we have a number of Stata do files (we are using version 15.1 due to limited funds in our department within a relatively large organisation). We have two sets of network drives one was to store personal files (which was moved to the cloud some time ago) and our shared network drive which we all have access to which was moved to the cloud earlier this week.

    I'm not an expert on Sharepoint and it appears that IT probably haven't thought through any issues where people use programmes that contain paths / file locations so they haven't been much help either so far.

    On our network drive, we previously 'mapped' our drives and set them up as T:\

    We have a lot of do files that are along the lines of:

    cd "T:\Datasets\Work area AAA"
    use dataset.dta

    so this would open T:\Datasets\Work area AAA\dataset.dta

    With IT moving all our files from a network drive to Sharepoint, we cannot open do files or stata files directly from Sharepoint (we can see Sharepoint via our Intranet or via an MS Teams channel), IT said that we could go to Sharepoint and create a shortcut to OneDrive. When I do this, we can then copy the full path form Windows Explorer. However, my path is now: "C:\Users\LOGIN_NAME\OneDrive - company name\Department name"

    The LOGIN_NAME is unique to me. So if I used that path / file location in the cd statement, my programme would not work for any of my colleagues as their LOGIN_NAME would differ.

    I came across the global command which I've not used before.

    Could I use the following in any way?

    global mainpath "C:\Users\LOGIN_NAME\OneDrive - company name\Department name"

    If I did this, could I then use the cd command to set the subfolder, and if so how would I do this.

    I tried - cd mainpath&"\Datasets\Work area AAA"

    but it didn't like this.

    Essentially the "C:\Users\LOGIN_NAME\OneDrive - company name\Department name" would be equivalent to our previously very short "T:"

    Regards,

    Mandy



  • #2
    I can't see that using a global macro would make any difference here. Essentially, you have a generic identifier LOGIN_NAME and each user must specify their log in name, unless Stata has some way to identifiy the login name, which would be a surprise.

    You could perhaps set it up so that each user would need to specify their identifier to a do-file that opens with

    Code:
    local name `1' 
    use C:\Users/`name'\OneDrive - company name\Department name"
    where the forward slash before the macro reference is essential to avoid a backward slash being interpreted as an escape character.


    Then if you are pi314159

    you could fire up the do file with

    Code:
    do whatever.do pi314169
    and your colleague exp271828 could go

    Code:
    do whatever.do exp271828
    and thereby the identifier would get passed to the do-file.

    Comment


    • #3
      Alternatively, it seems like you want to use the %username% environment variable in your path definition. The %username% variable in the path stores the name of the current logged in user. The windows operating system itself maintains this variable in the registry, so it's an operating system level solution rather than a stata level solution. Try this:

      Code:
      cd "C:\Users\%username%\OneDrive - company name\Department name"
      Note that it is possible to administratively disable this feature on a server. Hopefully IT hasn't done that, but if you type that path into windows file explorer and you get an error saying that accessing the path has been disallowed, that's the problem. In that case, you may need to reach out to IT to make the case that you need this feature enabled.

      Comment


      • #4
        Is there any information in the cret macros that could help Stata figure out where it is / where to go? For example in c(username) or c(pwd)?

        Comment


        • #5
          Hi Mandy, I believe you're describing a workflow similar to mine. I regularly use two different computers to access the same do-files stored in a Cloud drive, so their paths are slightly different depending on which computer I use. Here is what I do:
          1. I keep a "sticky note" on each desktop with the relevant code- i.e.
          Code:
          global path "/Users/myname/Library/CloudStorage/Box-Box/Research/myproject”
          2. This is the first command that I enter into Stata when I fire it up each day.
          3. I don't use cd at all. In all of my do-files, every path looks something like:
          Code:
          use "$path/Data/mydata.dta", clear
          Good luck!

          Comment


          • #6
            "sticky note"? see -help profile-. Or am I missing something? (Possible)

            Comment


            • #7
              I second #6. I use my profile.do file for the following:
              • set more off
              • set varabbrev off
              • set scheme <my_favorite_graph_scheme>
              • and a bunch of global macro declarations that define the top-level folders for my current projects.
              My collaborators have similar profile.do files, with the same macros referencing the relevant folders on their machines.

              Comment


              • #8
                You might also see what information you can get from the macro function environment

                See -help macro- under macro_fcn

                Comment

                Working...
                X