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]

st: RE: RE: relabeling variables using 2 datasets


From   Smets Lodewijk <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: RE: relabeling variables using 2 datasets
Date   Fri, 27 Apr 2012 11:11:16 +0000

Thanks for the solution!

 
Lodewijk Smets
PhD. candidate
Institute of Development Policy & Management (IOB)
University of Antwerp
Lange Sint-Annastraat 7 - Office S106
2000 Antwerp
 
Tel: +32 (0)3 265 5927
e-mail: [email protected]

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: vrijdag 27 april 2012 12:54
To: '[email protected]'
Subject: st: RE: relabeling variables using 2 datasets

use DB2 

forval i = 1/`=_N' { 
	local var = seriescodestata[`i'] 
	local l`var' = indicatorname[`i'] 
}  

use DB1 

foreach var of var * { 
	if "`: variable label `var''" == "" label var `var' "`l`var''" 
}

Nick 
[email protected] 

Smets Lodewijk

I want to relabel a large set of variables from one dataset (= DB1) using information from a second dataset (=DB2). 

DB1 contains numeric variables with the following names:  vAG_LND_PRCP_MM ,  vAG_SRF_TOTL_K2 , etc.

DB2 contains a string called seriescodestata which contains as values the same variable names as DB1, i.e. vAG_LND_PRCP_MM ,  vAG_SRF_TOTL_K2 , etc 
 
DB2 also contains another string called indicatorname which contains as values the labels I want to give to the variables in DB1

An example: 

DB1
vAG_LND_PRCP_NM                 vAG_SRF_TOTL_K2       etc.           

    327                             13781730

                                                     
DB2
Seriescodestata                         indicatorname

vAG_LND_PRCP_MM                average precipitation in depth (mm per year)

vAG_SRF_TOTL_K2                   surface area (sq. km)     
 
      etc.


Now I'm looking for a program code to automatically relabel the variables of DB1 using the information in DB2

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