>I'm sorry but your suggestion does not work. As - hopefully
>clear to all - I have described, it is about temporarily saving
>the label for e.g. Ax1 and then - after reshape long - apply the
>label of Ax1 to Ax. This should be automated for all variables I
>want to reshape so that I won't have to change the labels manually.
>
>Andrea
This question comes up every year. Here's a program I use.
It will grab a label from the earliest year. The line about
-cap local v: word 1 of `names'- can be adjusted or cycled
through, but that would be overkill.
Roy
*! reshapeL 0.9 Jun2008 by [email protected]
program define reshapeL
version 7
gettoken part1 rest1: 0, parse(",")
gettoken part2 rest2: part1, parse(" ")
foreach v in `rest2' {
cap unab names : `v'*
cap local v: word 1 of `names'
local count 0
local stop 0
while `count'>-50 & `stop'==0 {
local count=`count'-1
cap local last=trim(substr("`v'",`count',.))
capture confirm number `last'
if _rc!=0 {
local stop 1
}
}
cap local shortname=trim(substr("`v'",1,length("`v'")`=`count'+1'))
cap local l`shortname' : variable label `v'
di `"`v'"' _col(20) `"`l`shortname''"'
}
reshape `0'
foreach v in `rest2' {
cap label var `v' "`l`v''"
}
end
* create example data
webuse grunfeld,clear
reshape wide invest mvalue kstock time, i(company) j(year)
label var invest1935 "yum yum"
* preserves your labels as you go from wide to long
reshapeL long invest mvalue kstock time, i(company) j(year)
_________________________________________________________________
It’s easy to add contacts from Facebook and other social sites through Windows Live™ Messenger. Learn how.
https://www.invite2messenger.net/im/?source=TXT_EML_WLH_LearnHow
*
* 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/