Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: compare files, vars only


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: compare files, vars only
Date   Thu, 19 Feb 2009 11:41:53 -0500

David Kantor <[email protected]>:
These programs could both use a
 preserve
 clear
at the beginning, so it doesn't matter what data is in memory.

On Thu, Feb 19, 2009 at 11:20 AM, Austin Nichols
<[email protected]> wrote:
> David Kantor <[email protected]>:
> No, but see -vlc- on SSC.
> To compare sets of variables, you could just
>
> prog cvar, rclass
>  qui use in 1 using `"`1'"'
>  unab f: _all
>  qui use in 1 using `"`2"'
>  unab g: _all
>  loc i: list f & g
>  di as txt `"In `1'"' _n as res "`f'"
>  di as txt `"In `2'"' _n as res "`g'"
>  di as txt "In both" _n as res "`i'"
>  if "`i'"=="" di as err "No variables in common"
>  return local file1 `"`1'"'
>  return local vars1 `f'
>  return local file2 `"`2'"'
>  return local vars2 `g'
>  return local both `i'
> end
> cvar "`c(sysdir_base)'n/nlsw88" "`c(sysdir_base)'a/auto"
>
> Or did you want to compare an arbitrary number of files?  Also easy
> with -mac shift- :
>
> prog cvars, rclass
>  loc n=1
>  while `"`1'"'!="" {
>  qui use in 1 using `"`1'"'
>  unab f`n': _all
>  di as txt `"In `1'"' _n as res "`f`n''"
>  return local file`n' `"`1'"'
>  return local vars`n' `f`n''
>  if `n'==2 loc f: list f1 & f2
>  else loc f: list f & f`n'
>  loc n=`n'+1
>  mac sh
>  }
>  di as txt "In all files" _n as res "`f'"
>  if "`i'"=="" di as err "No variables in common"
>  return local all "`f'"
> end
> cvars "`c(sysdir_base)'n/nlsw88" "`c(sysdir_base)'a/auto"
> "`c(sysdir_base)'a/auto"
>
> On Thu, Feb 19, 2009 at 10:41 AM, David Kantor <[email protected]> wrote:
>> Hi.
>> Does anyone know of a program to compare the sets of variables in two data
>> files? What I have in mind is something akin to -cf-, but...
>>  it would not compare values -- only the names of variables;
>>  it would not care whether the two data files had the same number of
>> observations.
>>
>> I was planning to write such a program, but I wanted to be sure that it
>> hadn't already been done.
>> Thanks
>> --David
>
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index