Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Maarten Buis <maartenlbuis@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Compare two datasets wrt value labels |
Date | Thu, 29 Aug 2013 15:59:01 +0200 |
Here is how I would do this: *------------------ begin example ------------------ clear all program define my_store_labels args file results garbage confirm new file `"`results'"' if `"`garbage'"' != "" { di as err "only two files may be specified" exit 197 } use `file', clear label dir local labs `r(names)' tempname memhold postfile `memhold' str20 label int value str500 lab using `results' foreach lab of local labs { label list `lab' forvalues i = `=r(min)'/`=r(max)' { post `memhold' ("`lab'") (`i') (`"`: label `lab' `i''"') } } postclose `memhold' end program define my_compare_labels args file1 file2 garbage if `"`garbage'"' != "" { di as err "only two files may be specified" exit 197 } preserve tempfile labs1 labs2 qui my_store_labels `"`file1'"' `"`labs1'"' qui my_store_labels `"`file2'"' `"`labs2'"' use `"`labs1'"' qui merge 1:1 label value lab using `"`labs2'"' capture assert _merge != 1 if _rc { di as txt "The following labels exist only in " as result `"`file1'"' list label value lab if _merge == 1, clean noobs } capture assert _merge != 2 if _rc { di as txt "The following labels exist only in " as result `"`file2'"' list label value lab if _merge == 2, clean noobs } restore end my_compare_labels //// "http://www.stata-press.com/data/r13/auto2.dta"; /// "http://www.stata-press.com/data/r13/auto.dta"; *------------------- end example ------------------- * (For more on examples I sent to the Statalist see: * http://www.maartenbuis.nl/example_faq ) Hope this helps, Maarten On Thu, Aug 29, 2013 at 3:09 PM, Meisfjord, Jørgen Rajan <JorgenRajan.Meisfjord@fhi.no> wrote: > Thanks Nick, you gave me an idea. I have two datasets, form two different surveys. I am told that the variables are the same, and that codebooks are the same, too, but I want to verify. What I can do is: > > 1. ask for -labelbook- (alphabetized) in the first survey dataset. > 2. copy the result from the screen, and paste it into a new file as a string variable, say <labelbook_1> > 2. create a similar variable, <labelbook_2>, based on the second survey dataset > 3. assert labelbook_1== labelbook_2 > > Or something like that? > > Jørgen > > > -----Opprinnelig melding----- > Fra: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] På vegne av Nick Cox > Sendt: 29. august 2013 14:32 > Til: statalist@hsphsun2.harvard.edu > Emne: Re: st: Compare two datasets wrt value labels > > Not clear exactly what you are seeking. Presumably you have datasets that should be compatible but there are might be clashes in detail. > > Running -labelbook- in each dataset separately and looking at the results should help. > > A -decode- on each variable with value labels would produce string variables that should be compatible. > > (-multencode- (SSC) is a tool to ensure that the process can be reversed consistently.) Nick njcoxstata@gmail.com > > > On 29 August 2013 13:10, Meisfjord, Jørgen Rajan <JorgenRajan.Meisfjord@fhi.no> wrote: >> Is there a simple way to compare two datasets with respect to value labels? >> >> Thanks. >> >> Jørgen Meisfjord >> Dpt. of Health Statistics | Norwegian Institute of Public Health >> >> * >> * 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/ > > * > * 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/ > > * > * 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/ -- --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * 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/