Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Listing user-written ado files called by program

From   daniel klein <[email protected]>
To   [email protected]
Subject   st: Re: Listing user-written ado files called by program
Date   Wed, 7 Sep 2011 13:24:17 +0200


here is a skech of a program identifying user-written commands in a
do-file code. The syntax is

useduw <"path/file.ext">
(e.g., "c:/users/documents/myprog/foo.ado")

The program finds occurences of any command (i.e. ado-file) found in
the directories PLUS or PERSONAL in your (a)do-file code. All
user-written files used in the respective do-file are returned in
r(userwritten). Note that -useduw- might return too many files,
because the -filefilter- command that is used, searches for patterns.
Thus, the example line

reg price mpg weight foreign

in a (a)do-file will cause -useduw- to report that the -ice- command
(available from SSC) is used in the code. The reason is, that "price"
matches the pattern "ice". I have not found a solution to this problem

Here's the code (no help file, if you have problems just ask)

*! version 1.0.0 07sep2011 Daniel Klein

pr useduw ,rclass
	vers 12.0
	syntax anything(id = "dofile name") [, ADOPath(str)]
	* check file exists
	conf file `"`anything'"'
	* get directories
	if (`"`adopath'"' == "") loc adopath PLUS PERSONAL
	loc pwd `"`c(pwd)'"'
	foreach p of loc adopath {
		loc dirc : sysdir `p'
		cap cd `"`dirc'"'
		if !(_rc) loc dircts `"`dircts' `dirc'"'
		else di as txt `"(note : directory `dirc' not found)"'
		qui cd `"`pwd'"'
	* main
	tempfile tmp_file
	foreach dirct of loc dircts {
		* get subdirectories
		loc subdir : dir `"`dirct'"' dir "*"
		foreach subd of loc subdir {
			* get ado files
			loc adof : dir `"`dirct'`subd'"' file "*.ado"
			foreach ad of loc adof {
				* check occurences of command
				loc cmd : subinstr loc ad ".ado" ""
				filef `"`anything'"' `tmp_file' ,f("`cmd'") t("")
				if r(occurrences) loc uw `uw' `cmd'
				erase `tmp_file'
	* return results
	if (`"`uw'"' != "") {
		di as res _n "`uw'"
		ret loc userwritten `uw'

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index