Announcement

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

  • Problems with Stata finding user-written ado files

    Dear Stata users,

    I have written four programmes in .ado files but I don't manage for Stata programme to find the files and therefore, recognize the commands. The version of Stata that I am using is Stata/SE 15.1.
    First, I tried moving the .ado files into the PERSONAL path ("c:\ado\personal" folder), as I found this was the thing to do in the documentation. I did not manage to run the programme either calling the programme from another .do file or by using the the commands do or run followed by the filename in the prompt. I check online, and I tried to copy the programmes inside of subfolders named after the first letter of each programme, within the "c:\ado\personal" folder. It did not work either. I tried also copying the programmes into the OLDPLACE and PLUS paths, and I tried both options for each (with letter subfolders or without them). Nothing seems to work.

    I noticed two things when using the sysdir and the adopath commands. When looking at the PLUS, PERSONAL, and OLDPLACE paths, the c is written by default in lower case. I thought this might be the problem, as the actual directory seems to be specified with a higher case in my system. So I used sysdir set PERSONAL "C:\ado\personal" , to specify the path correctly, but this did not seem to fix it. Regarding the adopath result, I noticed that, for some reason, there paths are specified with back a forth slashes inconsistently, so I used again the sysdir set command to use only forth slashes to at least fix the inconsistencies, as I am unaware of why the forth slash happens in the first place. This also does not seem to help Stata find the programmes when I use, for example the do sliderado.ado (one of the names of the .ado files) or the same with run. I always get, in every of the described scenarios, a file not found. Anybody can help me understand what can be going on? Thanks in advance, I let a screenshot of the results when I run sysdir or adopath with the problems I described. Thanks in advance for your time.

    Click image for larger version

Name:	Captura de pantalla 2025-07-12 174125.png
Views:	1
Size:	27.1 KB
ID:	1779770

  • #2
    On the assumption that you are running Windows, the pathnames are not case-sensitive, and, while \ is the conventional path separator, / works equally well. So tinkering with those will not help you.

    The appropriate place to put sliderado.ado is in (PERSONAL), which in your setup is c:\ado\personal. If you believe you put it there, the first thing you should do is check that it really is in there. Open File explorer and navigate to c:\ado\personal and verify that the file sliderado.ado shows up. If it doesn't, use the Windows file search to find where it actually ended up and then move it to c:\ado\personal.

    If you can see it is there, but you nonetheless cannot run the program, the other thing to remember is that the name of the command must match the name of the file. So if the program is called -slider- and you have it in a file called sliderado.ado, Stata will not find it there. So you would either need to change the name of the program (both in the calling command and inside the ado file) to -sliderado-, or rename the file slider.ado.
    Last edited by Clyde Schechter; 12 Jul 2025, 11:18.

    Comment


    • #3
      In addition, suppose you have written myprog.ado and put the file in c:\ado\personal\m

      That is now an ado file. You would call it up with a call to

      Code:
      myprog
      (together with whatever else the program needs)

      not with do myprog or do myprog.ado, or any equivalent with run

      Under Windows, Stata allows forward slashes as well as backward slashes in filepaths. The main reason for that is that backslashes have another role to Stata as escape characters.

      Comment


      • #4
        To illustrate and expand on #3:

        Consider first the following code:
        Code:
        dis "Hello from this side!"
        which you save as a file called myprog1.ado, which you then put into your (PERSONAL) folder. And consider next the following code:
        Code:
        capture program drop myprog2
        program define myprog2 
            dis "Hello from the other side!"
        end
        
        capture program drop myprog3
        program define myprog3 
            dis "Hello from the other side again!"
        end
        which you save as a file called myprog2.ado, which you also put into the (PERSONAL) folder.

        Then here is what you get as a result of various commands:
        Code:
        . do myprog1
        file myprog1.do not found
        r(601);
        
        . run myprog1
        file myprog1.do not found
        r(601);
        
        . do myprog1.ado
        file myprog1.ado not found
        r(601);
        
        . run myprog1.ado
        file myprog1.ado not found
        r(601);
        
        . myprog1
        command myprog1 not defined by myprog1.ado
        r(199);
        
        . myprog2
        Hello from the other side!
        
        . myprog3
        command myprog3 is unrecognized
        r(199);

        Comment

        Working...
        X