Bookmark and Share

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]

SV: SV: st: value labels, rename and merge


From   "Tomas Lind" <[email protected]>
To   <[email protected]>
Subject   SV: SV: st: value labels, rename and merge
Date   Tue, 13 Apr 2010 16:50:09 +0200

The variable names and the example I gave was I bit simplified. When I tried
to manipulate your syntax to fit our specific problem I got into trouble.

The variable names are not just: 
Q1, Q2, Q3 ... . 

They are:
id, est, dat, Q1, Q2, Q3 ... . 

I do not simply want to change to:
 w_Q1, w_Q2, w_Q3 ... . 

I want to get rid of "Q" in the names and change the names to:
id, est, dat, q12p1, q12p2, q12p3 ... .

To change your code to add q12 instead of w_ is straight forward, but to get
rid of Q and get the loop running is more than I can achieve. Any help is
welcome.

/Tomas


> A software for making surveys on the web generates a small dataset 
> with variable- and value labels. Variable names are generic of the 
> form Q1, Q2, Q3 ? .Because many of names are already used in a large 
> dataset we rename the variables wQ1, wQ2, wQ3 ... before -merge-. When 
> we merge the web dataset to the large dataset (merge webdata using 
> largedata)  we get a note from Stata that ?Label already exist Q1? 
> (for a number of variables).
> 
> Also, when the webdataset is merged to the large dataset, value labels 
> in the web-dataset get its text from value labels in the large 
> dataset. This applies to all variables that shared the same name 
> before being renamed. For example value labels for wQ2 (a question 
> about age) has value labels for Q2 (a question about food).

You will have to change the name of the value labels manually. 
You can change all variable names and the associated value label names using
a loop like in the example below:

*------------- begin example ---------------- sysuse nlsw88, clear desc
foreach var of varlist _all {
	rename `var' w_`var'
	local lab : value label w_`var'
	if "`lab'" != "" {
		label copy `lab' w_`lab'
		label drop `lab'
		label values w_`var' w_`lab' 
	}
}
desc
*-------------- end example ----------------- (For more on examples I sent
to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

hope this helps,
Maarten



-----Ursprungligt meddelande-----
Från: [email protected]
[mailto:[email protected]] För Maarten buis
Skickat: den 12 april 2010 17:34
Till: [email protected]
Ämne: Re: SV: st: value labels, rename and merge

--- On Mon, 12/4/10, Tomas Lind wrote:
> What happens when
> local lab : value label w_`var'
> is executed?

The value labels that are attached to a variable have a 
name. The line you mentioned creates a local macro called 
`lab' containing that name if the variable w_`var' has 
value labels attached to it, otherwise the local macro 
`lab' contains "", i.e. an empty string.

You can read more about this in -help extended_fcn-.

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index