Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | daniel klein <klein.daniel.81@googlemail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: reshape and value labels |
Date | Tue, 23 Aug 2011 11:50:23 +0200 |
Leandro, 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. Best Daniel * * 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/