You can tell stata where to find the j identifier using the @ symbol. For
your example:
reshape long @03income @12ed, i(id) j(wave) string
Of course, if you have 450 vars (as your follow up post suggests), you may
not want to even use reshape or deal with clicking on one of each var and
editing the first letter to an @. You may also have a problem with the fact
that 03income and 12ed are not valid Stata varnames.
An alternative approach might be a foreach loop:
foreach wave in a b c d e {
use mydata, replace
keep id `wave'*
renvars `wave'*, presub(`wave' w)
gen str1 wave="`wave'"
capture append using mydatalong
save mydatalong, replace
}
I haven't tested this, but it should be close -- this loop assumes that all
you have in your dataset (named mydata) are your id var and the wave
prefixed vars. It should turn the data into long format with all varnames
prefixed with w after running this loop. You could change the w prefix by
adjusting the renvars command.
Michael Blasnik
[email protected]
----- Original Message -----
From: "Sarah A. Mustillo" <[email protected]>
To: <[email protected]>
Sent: Friday, February 07, 2003 5:02 PM
Subject: st: reshape question
> Hi -
>
> I am trying to reshape a dataset from wide to long and can't figure one
> small thing out. My variables are all named with the j identifier at the
> beginning of the variable, rather than at the end, e.g.,
>
> a03income
> b03income
> c03income
> d03income
> e03income
>
> a12ed
> b12ed
> c12ed
> d12ed
> e12ed
>
> etc.
>
> where a,b,c,d,e stands for wave. I want to:
>
> reshape long [many variables], i(id) j(wave) string
>
> but, of course, Stata seems to be looking to the end of my variables for
> the wave identifier when mine are at the beginning. I have been trying to
> use my limited programming skills to move the letter from the beginning to
> the end on all of the variables, but haven't been able to do it.
>
> Any suggestions?
>
> Thanks!
>
> Sarah
>
>
>
>
> Sarah A. Mustillo, Ph.D
> Center for Developmental Epidemiology
> Department of Psychiatry and Behavioral Sciences
> Duke University School of Medicine
> Box 3454
> Durham NC 27710
>
> 919 687-4686 x234
>
> *
> * 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/
>
*
* 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/