Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: FW: Assigning labels of 1 file into another file?


From   "Spiess, Sven Oliver" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: FW: Assigning labels of 1 file into another file?
Date   Wed, 12 Sep 2007 14:51:45 -0400

Thomas' suggestion is really neat.

If you would modify it like,

	file open varlab using "variablelabes.do", write replace
	  foreach var of varlist _all {
	    file write varlab "capture label `var' " `"""' "`: var label `var''"
`"""' _n
	  }
	file close varlab


You would actually generate a nice .do file right away. In combination with
Thomas' first post, you'd end up with two .do files to completely restore ALL
the labels from one file in another.

The only thing that's unfortunately left to do is to ASSIGN the value labels
generated by the "labels save" command to the respective variables in the target
data set once they are defined.


Best,
Sven-Oliver


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Steichen, Thomas J.
> Sent: Wednesday, September 12, 2007 2:17 PM
> To: [email protected]
> Subject: st: RE: FW: Assigning labels of 1 file into another file?
> 
> Probably a quicker way to label the variables is a variation on Sven's
> suggestion:
> 
> Run the following in file01 to construct a list of label commands on the
> screen ...
> 
>   foreach var of varlist _all {
>     di "label `var' " `"""' "`: var label `var''" `"""'
>   }
> 
> Copy the list of commands, paste it in a do file and run it in file02.
> 
> -----------------------------------
> Thomas J. Steichen
> [email protected]
> -----------------------------------
> 
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Spiess, Sven Oliver
> Sent: Wednesday, September 12, 2007 1:43 PM
> To: [email protected]
> Subject: st: FW: Assigning labels of 1 file into another file?
> 
> Hi Ziad,
> 
> In case you actually want to label variables not their values, I would
> probably
> try
> to work with (two) loops.
> 
> In the first data set you could use,
> 	foreach var of varlist _all {
> 		local `var'label : variable label `var'
> 	}
> 
> then add a command to open your new file and run something like,
> 	foreach var of varlist _all {
> 		label `var' `"``var'label'"'
> 	}
> 
> 
> Nevertheless, this would only work if your variables are named identically.
> If you want to do that in separate do files use global macros instead. Also
> I'm not sure if that will work out with the quotes in the second loop but
> it's
> worth a shot.
> 
> 
> I hope this can lead into the right direction.
> 
> Best
> Sven-Oliver
> 
> 
> > > -----Original Message-----
> > > From: [email protected] [mailto:owner-
> > > [email protected]] On Behalf Of Ziad El-Khatib
> > > Sent: Wednesday, September 12, 2007 1:02 PM
> > > To: [email protected]
> > > Subject: st: Assigning labels of 1 file into another file?
> > >
> > > Dear STATAlister
> > > I did lose records of a STATA file and now repeating the work again,
> > > to transfer the original file from Excel into STATA.
> > > To avoid re-labeling the variables again, is it possible to move the
> > > assigned labels from file01 into file02?
> > >
> > > Thank you and best regards
> > > ziad
> > > *
> > > *   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/
> 
> 
> *
> *   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/
> 
> -----------------------------------------
> CONFIDENTIALITY NOTE: This e-mail message, including any
> attachment(s), contains information that may be confidential,
> protected by the attorney-client or other legal privileges, and/or
> proprietary non-public information. If you are not an intended
> recipient of this message or an authorized assistant to an intended
> recipient, please notify the sender by replying to this message and
> then delete it from your system. Use, dissemination, distribution,
> or reproduction of this message and/or any of its attachments (if
> any) by unintended recipients is not authorized and may be
> unlawful.
> 
> *
> *   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/


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