Announcement

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

  • Change working directory for using multiple machines using - capture do -

    Dear Statalist,

    In my current job I used multiple computers to do my Stata work from multiple offices. Most of the computers are MACs, but one of them is a PC.

    As a result, each time I move locations to do work I need to always SLIGHTLY change the directory from which I am pulling data files into Stata in my do file programs.

    Here is an example. I start all my do files generally like this on a PC:

    Code:
    clear 
    
    set more off 
    
    global myfiles "c:\Users\rnb16003\filepath to stata files"
    
    cd "$myfiles" 
    
    import excel using "$myfiles\name_of_file.xls"
    But sometimes I am working on this file from the following place (from a mac):

    Code:
    clear
    
    set more off
    
    global myfiles "/Users/mac_username/filepath to stata file"
    
    cd "$myfiles" 
    
    import excel using "$myfiles/name_of_file.xls"
    Each time then I have to by hand change the file path that I'm working from and that's getting a bit tedious!

    I tried this, assuming capture would force the program to keep going until it hit the directory that worked on the machine I was on at the moment:

    Code:
    clear 
    
    set more off 
    
    capture global myfiles "c:\Users\rnb16003\filepath to stata files"
    capture global myfiles "/Users/mac_username/filepath to stata file"
    
    cd "$myfiles" 
    
    capture import excel using "$myfiles\name_of_file.xls" 
    capture import excel using "$myfiles/name_of_file.xls"
    This isn't working, though.

    Does anyone else have a trick I could use? Thanks so much for your help!


  • #2
    Use fastcd:
    https://ideas.repec.org/c/boc/bocode/s429301.html

    And create a list of filepaths on each machine, e.g.,
    Code:
    cd "filepath"
    c cur myfiles
    On both your mac and pc. Running ado's starting with the line
    Code:
    c myfiles
    will then switch to the correct location for each machine
    Last edited by Jorrit Gosens; 13 Mar 2017, 09:42.

    Comment


    • #3
      You're the best, Jorrit, thanks!

      Comment

      Working...
      X