Announcement

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

  • Use Stata program with same name in different directories

    Hi,
    I have a user-written program saved twice in my computer: once inside my system directory's usual path and a second one on a Dropbox folder shared with other users.
    The program has the same name in both folders but has a different version in each.
    Is there any way to tell Stata which of the two programs to use?
    Thanks
    P.S. I know it may not be recomendable to do this, but I need to keep 2 different versions of the program and haven't been able to find any other solution. Since the program I'm using is very complicated, I haven't been able to modify the name of one of two versions either.

  • #2
    If you type adopath then you will see the sequence of places on your system where Stata looks for a command that isn't part of the executable.

    If the directory or folder containing a command (foobar, say) is not explicitly one of those places, you need to navigate (using cd) to that folder for Stata to be able to find and use the program code. (In principle, that is not really an exception, as adopath always includes the current directory or folder . as a place to look.)

    If you also type

    Code:
    which foobar, all
    you will see zero or more places along your adopath where Stata can detect a version of foobar. In your case you are looking for two versions So move around using cd until Stata can see the version you want as first on its list.

    There's another twist. Once you've used one of those versions, the program code may remain in memory during the same session. To be sure Stata isn't using that,

    Code:
    program drop foobar
    will allow you to start afresh.

    I don't recommend for or against storing different programs with the same name. Stata won't get confused, but you may (and you certainly includes me, from time to time) I have several programs (some 20+ years old) in multiple versions on different computers, but these are the ways to work out which is which.

    But it can be simpler to change the program name in one case, which just means changing

    1. the name within the program statement at or very near the top of the .ado file

    2. the name of the program file to match

    3. the name of the corresponding help file

    4. mentions in the help file of the command name.

    That's usually a few minutes' work.

    I am guessing from your question that you're not a Stata programmer in a strong sense, but we're all Stata programmers in the broad sense if we ever typed one command that did what we wanted. It's worth knowing the facts above regardless of what level of learning you're at.

    Comment


    • #3
      Thanks Nick! Working around with cd seems to work perfect.
      However I found it might be easier to add a new adopath with the desired program's directory. If one uses adopath ++ then the path added and the programs within get first on the list (though one might want to remove the new adopath later).

      P.S.
      I had already tried changing the program name exactly as you said but had some problems. I'm doing this process for 2 programs (reghdfe and another one that calls on it). They're both quite long and complicated programs that call on several packages, so when I tried changing names Stata would show:
      is not a valid command name
      (error occurred while loading second_program.ado)
      r(199);
      Last edited by Santiago Cantillo; 03 Mar 2019, 08:25.

      Comment

      Working...
      X