LOOKFOR_ALL
Searches for variables/patterns in Stata data files (.dta)
If you want to use lookfor_all, then feel free to use Stata's command ssc install to download and install lookfor_all:
ssc install lookfor_all, replaceDisclaimer: There is no warranty on this software either expressed or implied. This program is released under the terms and conditions of GNU General Public License.
About lookfor_all
Programmers:
Date: 05Feb2007
Last updated: 06Oct2010
Searching within current directory
Zurab Sajaia (zsajaia@hotmail.com)
The World Bank
Michael Lokshin (mlokshin@worldbank.org)
The World Bank
Dan Blanchette (dan_blanchette@unc.edu)
The Carolina Population Center
The University of North Carolina
Chapel Hill, NC USA
The World Bank
Michael Lokshin (mlokshin@worldbank.org)
The World Bank
Dan Blanchette (dan_blanchette@unc.edu)
The Carolina Population Center
The University of North Carolina
Chapel Hill, NC USA
Date: 05Feb2007
Last updated: 06Oct2010
Searching within current directory
lookfor_all pattern[pattern [...]] [, options]
where pattern is a word that could be a name (or part of the name) of the variable and/or a word (or part of a word) in the variable label or value label name or value label if the vlabs option is specified or a word (or part of a word) in a note attached to the dataset or a word (or part of a word) in a note attached to a variable if the notes option is specified. lookfor_all only does case insensitive searches so searching for "test" may find "Test", "TEST", or "tESt" as well as "test".
Searching within current directory and subdirectories
lookfor_all pattern[pattern [...]] [, subdir
options]
Main
directory(path) an option to specify the root directory
where to search
subdir an option for searching subdirectories
describe an option to format the output
codebook another option to format the output
vlabs also search value label names and value labels
notes also search patterns in dataset notes and variable notes
dnotes also search patterns in dataset notes
dnotes also search patterns in variable notes
subdir an option for searching subdirectories
describe an option to format the output
codebook another option to format the output
vlabs also search value label names and value labels
notes also search patterns in dataset notes and variable notes
dnotes also search patterns in dataset notes
dnotes also search patterns in variable notes
Advanced
maxdepth(integer > 1) an option to specify how far down
a directory tree to search
maxvvar an option for Stata SE or Stata MP users to allow lookfor_all to open a dataset with up to 32,767 variables
dirfilter(regular expression) an option to specify a regular expression pattern that the subdirectory name has to satisfy in order to search files in that directory.
filter(regular expression) an option to specify a regular expression pattern that the file name has to satisfy in order to search the file.
maxvvar an option for Stata SE or Stata MP users to allow lookfor_all to open a dataset with up to 32,767 variables
dirfilter(regular expression) an option to specify a regular expression pattern that the subdirectory name has to satisfy in order to search files in that directory.
filter(regular expression) an option to specify a regular expression pattern that the file name has to satisfy in order to search the file.
Description
lookfor_all is an extension of the Stata program
lookfor.
lookfor_all searches through all Stata data files in a current directory and
subdirectories for the variable(s) with at least one of the specified patterns. Each pattern
could be a part/whole variable name and/or a word (part of the word) in the variable label.
lookfor_all outputs the list of data files where the pattern was found and the
list of variables within every data file that match the pattern. The files listed are
clickable. By clicking on the file, Stata loads that data file into memory.
lookfor_all can also search a directory other than the current directory by specifying the
directory(path) option for a search.
Options
Main
directory(path) specifies the path where
lookfor_all should start searching. By default lookfor_all searches
files in the current directory.
subdir if specified lookfor_all searches through all Stata data
files (
.dta ) in the current directory and subdirectories or the specified
directory and its subdirectories. If this option is not specified lookfor_all searches
only within the files in the current directory or the specified directory.
describe controls the way the variables that match the pattern are
outputted. By default lookfor_all outputs the variables following the name of the
data file they are in. Specifying describe makes Stata run the
describe command on the variables that
were found. You can control the output using the options of the Stata command
describe. These options are
simple short details fullname numbers.
codebook controls the way the variables that match the pattern are
outputted. Specifying codebook makes Stata run the
codebook command on the variables that
were found. The output will be the number of unique observations, mean, minimum, maximum and the
label of the matching variables. You can control the output using the options of the Stata command
codebook.
vlabs if specified lookfor_all will also search through the value
label names and value labels.
Advanced
maxdepth(integer > 1) if specified
lookfor_all will only search through all Stata data files
(
.dta ) as far down as the positive integer value that is specified.
If subdir is not specified and maxdepth is, then it is assumed
subdirectories should be searched.
maxvar if specified and you are using Stata SE or MP, lookfor_all
will temporarily set maxvar to the
maximum which is 32767 so that lookfor_all can search a dataset that contains more
variables than maxvar is currently set to
be able to open. Changing the setting of
maxvar will stop the
page up key from being able to access command history. So if you set
maxvar to 32767 yourself before running
lookfor_all, lookfor_all will not need to set it and you will be able to
access your command history with the page up key after running lookfor_all.
dirfilter(regular expression) if specified
lookfor_all will only search through all Stata data files
(
.dta ) in the current directory or specified directory and only
subdirectories that satisfy the
regular expression pattern.
rfilter(regular expression) if specified
lookfor_all will only search through Stata data files
(
.dta ) that satisfy the
regular expression pattern.
Examples of searching within the current directory
. lookfor_all edu . lookfor_all edu, describe simple . lookfor_all edu, de short
Examples of searching the current directory and sub-directories
. lookfor_all edu, sub . lookfor_all edu, maxdepth(3) de fullnames . lookfor_all edu, sub codebook vlabs . lookfor_all edu, dirfilter(data) codebook
Examples of searching the specified directory
. lookfor_all edu, sub de dir("c:\data\")
. lookfor_all edu, sub de dir("c:\data\") filter(^wave1)
Useful suggestions and feedback by Phil Bardsley and Michael Norman Mitchell are gratefully acknowledged.
This Michael Norman Mitchell's Stata Tidbit of the week on lookfor_all.
Also see


