Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Comparing datasets


From   "Raphael Fraser" <raphael.fraser@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Comparing datasets
Date   Tue, 16 Sep 2008 01:52:45 -0500

David,

I think that should be
des using auto1, varlist

and not

des auto1, varlist

thanks to all

Raphael



On Mon, Sep 15, 2008 at 11:25 PM, David Kantor <kantor.d@att.net> wrote:
> 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."
>>  }
>> }
>> [...]
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index