Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: reshape and value labels

From   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: reshape and value labels
Date   Tue, 23 Aug 2011 11:50:23 +0200


I understand that you renamed your "pretty long pieces of string"
assigning a prefix and using the -abbrev()- function because of
problems with the maximum string length allowed (you probably are
referring to the maximum characters allowed in variable names rather
than string length here). This seems indeed cumbersome. I suggest
renaming the variables with a common name and a running number (Your
variables have to appear in the correct -order- in your dataset). This
is easily implemented.

loc i 0
foreach v of varlist coffeearabicacentskgcurrent-crudeoilbrendtbblcurrent {
    ren `v' stub_name`++i'
    loc name`i' : var l stub_name`i'

The loop will rename the variables and save their variable labels. You
now reshape your dataset.

reshape long stub_ ,i(date) j(name)

Now you replace the variable names in the string variable "name" with
their respective variable labels drawing on local i that still holds
the number of variables from step 1.

forval j = 1/`i' {
    replace name = "`name`j''" if name == "name`j'"

Should I have missed something, or someone has a more elegant
solution, please let me know.

*   For searches and help try:

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