Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Merge with "value labels" of same name but differnet contents


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   st: Re: Merge with "value labels" of same name but differnet contents
Date   Tue, 12 Oct 2004 18:57:21 +0900

Jens Lauritsen wrote:

I tried to find an ado for merging datasets to handle the situation that
the files have the same names for value label definitions but the contents
were different.
e.g.
dataset one: label v1  is: 1 yes 2 no applied to variable d1
dateset two: label v1 is : 1 small 2 medium 3 large applied to variable s1

When merging data either d1 or s1 gets wrong labels.
Any suggestions apart from going back to the definition in the old files
and renaming there ? (before I write an ado to handle this).

----------------------------------------------------------------------------

Take a look at the label utilities suite of commands by Nick Cox.  -findit
labutil-.  You might also be able to use -tempfile- in combination with
Patrick Joly's -varlab- (-varlab save- and then -varlab load- after
your -merge-), but it seems that the most direct way is to use -labvalclone-
from the -labutil- suite.

Joseph Coveney

* The first 17 lines just creates the two datasets for illustration
clear
set more off
set obs 6
generate byte d1 = mod(_n, 2) + 1
label define v1 1 No 2 Yes
label values d1 v1
generate byte rec = _n
sort rec
save one
clear
set obs 6
generate byte s1 = mod(_n, 3) + 1
label define v1 1 Small 2 Medium 3 Large
label values s1 v1
generate byte rec = _n
sort rec
save two
* Illustration begins here
use one, clear
labvalclone v1 v2
label drop v1
merge rec using two
label values d1 v2
slist, label noobs
exit




*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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