Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: RE: compare files via merge
From
David Kantor <[email protected]>
To
[email protected]
Subject
Re: st: RE: compare files via merge
Date
Fri, 03 Jan 2014 11:53:09 -0500
Hello Rasool,
Thanks very much. I will look into your suggestions.
--David
At 06:09 AM 1/3/2014, you wrote:
Dear David,
I have made an ado file for generating list if id discrepancies in
two data files. May be this will help you. Copy the following code
and save an ado file in your working directory. Then run as:
----cmpids file1.dta file2.dta idvar----
You can change the program's drop statement if you want the list of
matched ones.
Change this line
qui drop if count_one == 1 & count_two == 1
with this one.
qui drop if count_one ~= 1 & count_two ~= 1
Best of luck.
Rasool Bux
*********program begin ************
capture program drop cmpids
program define cmpids
args fone ftwo idv
if `"`fone'"' == "" | `"`ftwo'"' == "" {
di as err "Two data files are required; nothing to do"
exit 498
}
if "`fone'" == "`ftwo'" {
di as err "Same file is not used for
structure compare"
exit 498
}
else {
local idvar "`idv'"
if substr("`fone'", -4, 4) !=
".dta" local fone "`fone'.dta"
if substr("`ftwo'", -4, 4) !=
".dta" local ftwo "`ftwo'.dta"
qui use "`fone'", clear
qui contract `idvar', freq(count_one) nomiss
qui label variable count_one "Freq in file 1"
qui save freq1.dta, replace
qui use "`ftwo'", clear
qui contract `idvar', freq(count_two) nomiss
qui label variable count_two "Freq in file 2"
qui save freq2.dta, replace
qui use freq1.dta,clear
qui merge 1:1 `idvar' using freq2.dta, norep
qui replace count_one = 0 if count_one==.
qui replace count_two = 0 if count_two==.
qui drop if count_one == 1 & count_two == 1
qui drop _merge
qui save freqtbl.dta, replace
qui erase freq1.dta
qui erase freq2.dta
brow `idvar' count_one count_two
}
end
****************** program end **********************
[...]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/