Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Conserving variables and value labels while reshaping wide to long


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: RE: Conserving variables and value labels while reshaping wide to long
Date   Thu, 23 May 2013 12:58:11 +0100

Your restructuring can be done in several ways. Here is another

preserve
gen wave = 1
rename (da03 da04) (a03 a04)
keep id a03 a04 wave
save wave1
restore
gen wave = 2
rename (ea03 ea04) (a03 a04)
drop da03 da04
append using wave1

I've not tried it, but I am hopeful on your behalf that your labels
will be kept.

Nick
njcoxstata@gmail.com


On 23 May 2013 12:22, natalia malancu <natalia.malancu@gmail.com> wrote:
> Hi David,
>
> thank you for the suggestion. I was already aware of it, however it is
> only relevant for stata 11 users (I'm using 12). Moreover, I'm not
> sure how to go around things given the string component in my case. I
> would prefer not having to generate a new variable via substr()
>
> Natalia
>
>
> On Wed, May 22, 2013 at 9:43 PM, Radwin, David <dradwin@rti.org> wrote:
>> Natalia,
>>
>> Keeping variable labels after -reshape- is a FAQ, at least through
>> version 11:
>>
>> http://www.stata.com/support/faqs/data-management/apply-labels-after-res
>> hape/index.html
>>
>> David
>> --
>> David Radwin
>> Senior Research Associate
>> Education Studies Division
>> RTI International
>> 2150 Shattuck Ave., Suite 800
>> Berkeley, CA 94704
>> Phone: 510-665-8274
>>
>> www.rti.org
>>
>>
>>> -----Original Message-----
>>> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
>>> statalist@hsphsun2.harvard.edu] On Behalf Of natalia malancu
>>> Sent: Wednesday, May 22, 2013 12:18 PM
>>> To: statalist@hsphsun2.harvard.edu
>>> Subject: st: Conserving variables and value labels while reshaping
>> wide to
>>> long
>>>
>>> Hi guys!
>>>
>>> I have the following data structure
>>>
>>> id da03 da04 ea03 ea04
>>>
>>> where d refers to wave 1 of my data and e refers to wave 2.
>>>
>>> after reshaping I am left with the variables a03 and a04.
>>>
>>> How would a loop structure look like in order to preserve both the
>>> variable and value labels?
>>>
>>> Thanks,
>>> Natalia
>>
>>
>>
>> *
>> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index