Me too. What rule maps X42 to X5?
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Philipp Rehm
Sent: 01 May 2008 21:11
To: [email protected]
Subject: Re: st: Deleting Characters of a Var Name by index Number
Do you have something like this in mind?
foreach var of varlist X31 X42 X53{
rename `var' `=substr("`var'",1,2)'
}
I am slightly confused since I think that your two wishes:
(1) [X and only the second to last character from the *left* of `var'];
(2) X31 would then be renamed X1 and X42 would be X5 and so on;
don't match.
HTH,
Philipp
Kyle Caswell wrote:
> Hello.
>
> I would like to write a macro that renames variables by deleting a
> specific character of a variable name for a group of variables.
>
> For example, suppose that I have variables X31 X42 X53 and so on. I
> would like to wite a macro that does something like the following:
>
> foreach var of varlist X31 X42 X53{
> rename `var' = [X and only the second to last character from the
> *left* of `var']
> }
>
> That is, X31 would then be renamed X1 and X42 would be X5 and so on.
>
*
* 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/