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]

Re: st: Retaining variable labels when converting from wide to long form


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Retaining variable labels when converting from wide to long form
Date   Tue, 8 Jan 2013 14:42:16 +0000

See also

1. help -reshape- on the string option

2. FAQ

FAQ     . . . . . . . . . . . . . . . . . . . . . . . .  Problems with reshape
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        12/03   I am having problems with the reshape command. Can
                you give further guidance?

http://www.stata.com/support/faqs/data-management/problems-with-reshape/

first explicit "Question ... Answer"

Nick

On Tue, Jan 8, 2013 at 2:29 PM, daniel klein <[email protected]> wrote:

> have a look at -longshape- (Cox, SSC). I never used it, but it might
> do what you want.

Tim Stapleton

> I've converted a .dta file which was in the following format to the long
> form to analyse the responses of each individual surveyed:
>
> [...]
> Using the command:
>
> reshape long m1_@ m2_@ m3a1_@ m3a2_@ m3b_@ m4a_@ m4b_@ m5a_@ m5b_@ m6_@ m7_@
> m8_@ m9_@ m10_@ m11a1_@ m11a2_@ m11b1_@ m11b2_@ m12_@ m13a1_@ m13a2_@ m14_@
> m15a1_@ m15a2_@ m15b1_@ m15b2_@ m16_@ m17_@ m18_@ m19_@ m20_@ m21_@ m22_@
> m23_@ m24_@ m25_@ m26_@ m27_@ m28_@ m29_@ m30_@ m31_@ m32_@ m33_@ m34_@
> m35_@ m36_@ m37_@ m38_@ m39_@ m40_@, i(serial) j(id 01 02 03 04 05 06 07 08
> 09 10)
>
> [...]
> The problem is that in the process I lose the variable labels (i.e. m1_ is
> no longer labelled "1. gender" and so on).
> Does anyone know how to preserve the variable (without relabelling or
> renaming each variable)?
>
> I notice that if I omit the specification "j(id 01...)" from the command
> above, the labels are preserved but because of the naming convention used
> for the variables (m1_01 to _10 and so on), running this command does not
> transform the data correctly.
>
> Also for future reference does anyone know how to write this command more
> succinctly?  If I summarise the new variable names in the format recommended
> in the varlist help file (e.g. "m16_@-m40_@"), I get an "implied name too
> long" error.
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index