One command that may be useful is:
This will describe the contents of "filename", and a list of the variables it contains will be contained in the return value r(varlist)Code:describe using filename, varlist
So you could then do, for an ugly example:
Here's an example from the built-in auto dataset (I changed paths to the system path just to make the example filename shorter):Code:describe using filename, varlist if strpos(r(varlist), "myvar")!=0 { display "filename contains the variable myvar" } else { display "filename does not contain the variable myvar" }
Of course the examples are ugly but they're just to show how to use -describe- and r(varlist) to determine if a variable's present. You could probably combine the gist of the above code with a list of file names and some binary indicators...Code:. describe using auto.dta, varlist Contains data 1978 Automobile Data obs: 74 13 Apr 2009 17:45 vars: 12 size: 3,478 ------------------------------------------------------------------------------- storage display value variable name type format label variable label -------------------------------------------------------------------------------------------------------------- make str18 %-18s Make and Model price int %8.0gc Price mpg int %8.0g Mileage (mpg) rep78 int %8.0g Repair Record 1978 headroom float %6.1f Headroom (in.) trunk int %8.0g Trunk space (cu. ft.) weight int %8.0gc Weight (lbs.) length int %8.0g Length (in.) turn int %8.0g Turn Circle (ft.) displacement int %8.0g Displacement (cu. in.) gear_ratio float %6.2f Gear Ratio foreign byte %8.0g origin Car type ------------------------------------------------------------------------------- Sorted by: foreign . if strpos(r(varlist), "price")!=0 { . display "auto.dta contains the variable price" auto.dta contains the variable price . } . else { . display "auto.dta does not contain the variable price" . } . if strpos(r(varlist), "fakevar")!=0 { . display "auto.dta contains the variable fakevar" . } . else { . display "auto.dta does not contain the variable fakevar" auto.dta does not contain the variable fakevar . } .
Good luck!





Reply With Quote
