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]

Re: st: Searching for files with a particular *value* of a variable

From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Searching for files with a particular *value* of a variable
Date   Thu, 1 Mar 2012 07:53:10 +0000

You can approach this in various ways. I haven't used either of the
user-written programs you mentioned but let's just approach it from
first principles:

local present
quietly foreach f in <filelist> {
            use `f'
            count if <varname> == <value>
            if r(N) local present `present' `f''

di `present'

You'd need something subtle if your filenames contain spaces.


On Thu, Mar 1, 2012 at 6:23 AM, Partho Sarkar <[email protected]> wrote:

>  I need to search through a large number of files in a folder (with
> subfolders) for the presence of a particular *value* of a variable.  I
> know (and have found very useful) the -lookfor_all- program ( by Zurab
> Sajaia, Michael Lokshin and Dan Blanchette ) (SSC download) can find
> occurences of variables, labels etc in a directory path.  I also just
> discovered Daniel Klein's -lookfor_val-  (SSC download), which can
> "Search for value patterns in *current* data set", but it doesn't
> offer an option to search through a list of files . Can anyone here
> suggest a way out?
> [ I can think of a way to combine the above two utilities, using
> -lookfor_all-  to locate the files, and then  -lookfor_val-  to loop
> through all the files thus found, and using the returned results for
> each file  to flag the matching files.  But since  -lookfor_all-  does
> not (as far as I can see) return the names of the files it finds in a
> stored result (only displaying them on the screen), I cannot easily
> think of a relatively simple process to get what I need by combining
> the two programs. ]

*   For searches and help try:

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