Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renaming variables using the loop - changing the number attached to the variables

    Hi,

    I have 516 variables named as m229 to m744.
    I want to rename each one of them so that m229 becomes m1, m230 becomes m2, ..., m744 becomes m516.
    In a way, I want to subtract the 228 from the number given in the name of the each of the variable.

    Hence I tried using the following loop:

    forval i = 229(1)744 {
    rename m`i' m`i-228'
    }
    The loop ran and didn't show any error but no change in the name of the variables.

    I am showing the sample output for your reference.


    . forval i = 229(1)230 {
    2. ren m`i' m`i-228'
    3. }
    (all newnames==oldnames)
    (all newnames==oldnames)

    Thanks in advance.

  • #2
    you did not supply a dataexample so I did not test this but I think that example 16 in
    Code:
    help rename group
    can be followed to do what you want with no loop needed

    Comment


    • #3
      Thanks @Rich Goldstein

      Comment

      Working...
      X