Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



foreach v of var VAR* {
      local insert : di %02.0f  14 +  real(substr("`v'", 4, 2))
      local suffix = substr("`v'", 6, .)
      rename `v'  VAR`insert'`suffix'
}

-renvars- (SJ) would allow a one-line solution, but it would look
quite like the above and be no faster.

Nick
[email protected]

On 13 January 2014 11:14, Richard Moverare <[email protected]>

> I have a minor problem renaming some variables. I am sure there is
> some simple solution, but at the moment I can't find it. I have a
> dataset with variables named as follows:
>
> VAR02_1
> VAR02_2
> VAR02_3
> VAR03
> VAR04c
> VAR05_1
> VAR05_2
> and so on
>
> The structure is VARXX and then sometimes a few more characters. I
> would like to change these numbers, i.e. XX, by increasing their value
> with, say 12. The characters following XX should not be changed. So
> that, in my example, I get:
>
> VAR14_1
> VAR14_2
> VAR14_3
> VAR15
> VAR16c
> VAR17_1
> VAR17_2
> and so on
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index