-------------------------------------------------------------------------------
help cfvars
-------------------------------------------------------------------------------

Compare variable name lists in two data sets

Syntax

cfvars filename1 [filename2]

Description

cfvars compares the lists of variable names in Stata data file filename1 and

either Stata data file filename2, if specified,

or the data currently in memory, otherwise.

cfvars prints lists of variable names in both datasets (if any) and in each dataset but not the other (again, if any in either case).

Remarks

Note that filenames must be those of Stata .dta files and must be enclosed in double quotes whenever they include spaces. The .dta extension is not required and will be added if absent.

Note also that there is absolutely no checking of variable values. That is the job of cf.

Examples

. sysuse auto . drop mpg . cfvars auto.dta

. cfvars frog.dta toad.dta . cfvars frog toad

. cfvars "c:\somewhere\older frog.dta" frog.dta

Saved results

r(both) list of variable names in both r(oneonly) list of variable names only in first-named file r(twoonly) list of variable names only in second-named file or data in memory r(same) 1 if datasets have same variable names, 0 otherwise

Note that r(same) is always returned. The other results are returned only if not empty. Even if not returned, a subsequent test such as "`r(both)'" == "" will return 1 (true) as usual.

Author

Nicholas J. Cox, Durham University, UK n.j.cox@durham.ac.uk

Acknowledgments

This problem was suggested on Statalist by David Kantor on 19 February 2009. Several people contributed ideas to the resulting thread.

Also see

help for cf, describe, ds, unab