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: Comparing Variable Name Labels Between Datasets
From
Tim Wade <[email protected]>
To
[email protected]
Subject
Re: st: Comparing Variable Name Labels Between Datasets
Date
Fri, 14 May 2010 09:47:05 -0400
Beth, how about something like this:
*save variable labels as local macros
sysuse auto.dta
foreach var of varlist _all {
local `var'd1: variable label `var'
}
clear
sysuse auto.dta
*create erros in variable lables and save as local macros in second dataset
label var make "price"
label var price "Make"
foreach var of varlist _all {
local `var'd2: variable label `var'
}
*compare and list differences
foreach var of varlist _all {
capture assert "``var'd1'"=="``var'd2'"
if _rc~=0 {
if "``var'd1'"~="``var'd2'" {
di "Error in `var'"
di "First label: ``var'd1'"
di "Second label: ``var'd2'"
}
}
}
Error in make
First label: Make and Model
Second label: price
Error in price
First label: Price
Second label: Make
hope this helps, Tim
On Thu, May 13, 2010 at 10:23 PM, Beth Gifford <[email protected]> wrote:
> Hello
> We are working with a large dataset that goes back to 1976-through
> current. One challenge in working with these data is that the
> variable names change frequently (the same variable may be name V453
> one year and V455 the next). However, the variables are labeled. So
> I'd like to do the following:
> a) for each year, pull together a dataset with about 75 variables (DONE)
> b) rename the variables to something sensible and also consistent
> across years (ex. from 1976-2008 the variable for gender would always
> be named gender) (DONE)
> c) compare the variable name labels across years to double check that
> the new sensibly named variable is measuring what I think that it is
> measuring. (HELP)
> d) append the datasets (easy)
> *I have looked at cf, cf2 and cf3 but I think that they only let me
> compare observations. Encode won't work because it works on the
> valuable labels but not the name labels
> I am using Stata SE 11.0 on a windows machine. This problem is
> applicable to working with Monitoring the Future data as well as the
> Youth Risk Behavior Surveys.
>
> --
>
>
>
>
>
> --
> Elizabeth Gifford, PhD
> Research Scientist
> Center for Child and Family Policy
> Duke University
> 214 Rubenstein Hall
> Box 90545
> Durham NC, 27708-0545
> Work Phone: 919-613-9294
> Fax: 919- 684-3731
> http://www.duke.edu/~ejg141/
> Check out my new creation:
> http://substanceabuse.ssri.duke.edu/
>
> *
> * 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/