Announcement

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

  • Problem with rename in a loop

    Hello I am trying to rename some variables within a loop, but it returns me error.
    I have some variables like F10_sadk_ifs_t10y_ed4_qe_90 and I want them as F10_sadk-ifs_t10y_ed4_qe_90.
    I tried this:
    Code:
       foreach a in F10 F15 {
       foreach b in sapk sadk {
       foreach c in t3m t6m t1y t2y t3y t5y t7y t10y {
       foreach f in mp1 mp2 mp3 mp4 ff1 ff2 ff3 ff4 ed1 ed2 ed3 ed4 {
       foreach s in qe nqe
       foreach t in 68 90
      
     rename `a'_`b'_ifs_`c'_`f'_`s'_`t' `a'_`b'-ifs_`c'_`f'_`s'_`t'
     }
     }
     }
     }
    Last edited by Alberto Lopez; 20 Feb 2019, 02:08.

  • #2
    Var names cant have dash. Use underscore.

    Edit:
    I do now see that this would negate the renaming loop altogether. So maybe just leave as is?
    See section 11.3 here: https://www.stata.com/manuals13/u11.pdf for naming rules

    Code:
        foreach a in F10 F15 {
       foreach b in sapk sadk {
       foreach c in t3m t6m t1y t2y t3y t5y t7y t10y {
       foreach f in mp1 mp2 mp3 mp4 ff1 ff2 ff3 ff4 ed1 ed2 ed3 ed4 {
       foreach s in qe nqe {
       foreach t in 68 90 {
      
     rename `a'_`b'_ifs_`c'_`f'_`s'_`t' `a'_`b'_ifs_`c'_`f'_`s'_`t'
     }
     }
     }
     }
     }
     }
    Last edited by Jorrit Gosens; 20 Feb 2019, 02:18.

    Comment

    Working...
    X