Announcement

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

  • Master .do file using global directories

    I'm trying to run the following code:

    ==========================
    clear
    set more off

    *Specify main directory's path
    global path "/Users/markburgunder/Desktop/school/QM IV/QM IV data"

    *Define sub directories
    global temp "$path/temp"
    global DO "$path/DO"
    global data "$path/California NO2"

    * Go to the main directory
    cd $path

    *log file
    capture log close
    log using california.smcl, replace

    * import and append california NO2 data & generate month/year variables
    run California_makedata

    * California county NO2 summary graphs
    run California_figures
    ============================
    and run into problems.

    In the .do files I'm trying to run, I also specify a working directory using cd. Obviously, my .do files and .dta files are in different subdirectories, but I don't think this should be a problem.

    I'd like to be able to add another .do file for regressions, and have the 3 .do files talk to each other.

    Ultimately I will compile more data from other states, and need to replicate this .do file over and over.

  • #2
    Mark, there is only one directory that is current for Stata at any moment in time (it is not specific to a file) and you can change it from do file, from command line, or from the menu.
    Your description is not very accurate, but I read it as you are relying on certain directory to be current when you run your master file, and subordinate files may distort it. If so, enforce it again by changing the directory after calling the subordinate do file.

    It might also be useful to define an intermediate level (country). Where data preparation, tabulation and graphing will be handled and the master file just iterates over countries.

    Best, Sergiy Radyakin

    Comment


    • #3
      What kind of trouble do you run into? When your do files talk to each other, what will they have to say? Your question is extremely vague.

      I can offer you one piece of advice, that may or may not relate to your unspecified difficulties, but seems like it could be related. Global macros are an inherently unsafe programming practice. If your California_figures.do file defines it's own global macro path, do, temp, or data, it will clobber what you have defined in the master do-file and when you then try to make use of those farther down, they will have the wrong information, perhaps sending Stata careening off into the wrong directories to find files that only exist elsewhere. I have been using Stata since 1994, and only twice have I found a situation where it was actually necessary to use global macros. And because of their inherent danger, they should only be used when there is no alternative. Depending on how your slave do-files need to "talk to each other" this may be one of those circumstances--on the information shown there is no way to tell. But given the rarity of such situations, I would bet against it a priori. Depending on what problems you are having, they might just go away if you convert all your global macros to local macros (which are 100% safe).

      Then again, your problems may have nothing to do with this. I think you will have to give much more information about the nature of the problem and ask more specific questions.

      Added: Crossed with #2.

      Comment

      Working...
      X