Re: st: Re: Comparing datasets

Following Eva's suggestion, you don't need to -use- a dataset to get
its variables:

des somedataset, varlist
local first `r(varlist)'

des someotherdataset, varlist
local second `r(varlist)'

(You can put in -quietly:- if you like.)

This can be followed by Eva's comparison of first and second, or you
can use macrolists:

local first_not_second : list first - second
local second_not_first : list second - first

disp "not present in the first file: `first_not_second'"
disp "not present in the second file: `second_not_first'"

(Actually, that can be condensed further, but I'll let that go for now.)

See -help macrolists-.

----

On -cf-, another disadvantage in this situation is that it requires
the same number of observations in each dataset.

HTH
--David

At 05:18 PM 9/15/2008, you wrote:

If you use -cf- you have to use it in both directions, to be on the
safe side. However, -cf- compares all values as well, which will
clutter the output considerably if these are actually two different
datasets with the same variable names.
Here is a way to avoid this problem. The example uses the auto data.
****
sysuse auto, clear
drop foreign
save myauto1
sysuse auto, clear
drop price head
save myauto2
qui ds
local second `r(varlist)'
use myauto1, clear
qui ds
local first `r(varlist)'
foreach x of local first {
if strpos("`second'","`x'") == 0 {
di in yellow "`x' is not present in the second file."
}
}
foreach x of local second {
if strpos("`first'","`x'") == 0 {
di in yello "`x' is not present in the first file."
}
}
[...]