In the case of p1
foreach v of var *p1* {
local new : subinstr local v "p1" ""
rename `v' `new'p1
}
Minimalists might prefer
foreach v of var *p1* {
rename `v' `: subinstr local v "p1" ""'p1
}
(neither tested)
Nick
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Guanghui Li
> Sent: 05 November 2004 00:45
> To: [email protected]
> Subject: st: rename a lot of variables
>
>
> Dear all,
> I have personnel data from 6 companies and the maximum number
> of employees
> in those companies is 18. There are 27 variables for each
> employee. The data
> is shaped in the wide form, therefore, I have 18*27=486
> variables in total.
>
> I would like to reshape the data to a long form. However, the
> way these
> variables are named is hard for me to do the reshape command.
> c1p1a1 c1p1a2 .....
>
> c2p1
>
> c3p1
>
> c4p1e1 c4p1e2 .....
>
> c5yp1
>
> c05mp1
>
> .....
> The p1 in each of those variable names represent employee 1.
> Sometimes p1
> is at the end of the variable names, but most of the times it
> is in the
> middle of the variable names (342 in total) . I would like to
> move p1 to the
> end of the variable name so that I could define 1-18 to be
> the "j" in the
> reshape command.
>
> I have checked the commands "rename" "renvars" "renpfix"
> "rensfix", but none
> of them seems to be able to do this in a quick and easy way.
> Please give me
> some suggestions.
>
> Thank you in advance.
>
> Guanghui Li
>
>
>
>
> *
> * 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/