Announcement

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

  • Can I simulataneously move directories when I utilize the commands "use" and "save" using relative paths?

    So I have organized my files such as in the Superproject folder I have folders called Scripts, Data, Analysis1, Analysis2, etc. Within Scripts folder I have the main script and all the nested scripts, that is all the .do files. So what I want to do is: write a command in the .do file that is placed within Scripts, that will navigate back, go to Data folder, and use the file `1'data. Here `1' refers to the year that I hope to use as the argument. After all the analysis is done I want to save the outputs in the Analysis1 folder, so I want it to navigate back a directory, then go into Analysis1 and save it as `1'analysis.

    What kind of command using relative paths will work here?

    Code:
    use ../Data/`1'data, clear
    Code:
    save ../Analysis1/`1'analysis, replace

  • #2
    Type:
    Code:
    help cd

    Comment


    • #3
      Thanks Tiago, but using cd changes the working directory itself, rather than using the file from a different directory

      Comment


      • #4
        Hi, Dev.
        If you can provide us with more detailed information about what you need, and I'm confident that either I or other Stata users can help. It seems I did not understand your post.

        Comment


        • #5
          Dev, it looks to me like you want to be able to define relative paths from a working directory one level up from the current working directory. If so, Tiago is right, you can do this with cd.

          Code:
          cd ..
          use /Data/`1'data, clear
          save /Analysis1/`1'analysis, replace
          You are right that cd changes the working directory only, but it is fairly straight forward to use the cd command in combination with other commands.

          Comment


          • #6
            Both of Dev's commands work, assuming that he started in his scripts folder. Notice that when you run a do file, that will not set your working directory to where that file is stored. When you installed Stata you chose where Stata is by default, and you can use cd to change the current working directory. I usually do that only once in a project, in the main.do file. That way I can easily run my project on multiple computers just by changing that one line.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              Thanks a lot for all your help. I think Maarten's comment resolves my query. I was assuming that my working directory changes when I run a .do file. I'll try to be a little nifty with relative paths

              Comment

              Working...
              X