Announcement

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

  • Loop renaming from labels

    my variables are named B, C, D, E,... EY (because i imported from excel), and they have labels such as 512BXIPI_BP6_USD.Q, 513BXIPI_BP6_USD.Q.....

    I want to create a loop to convert the variable names to be y512, y513.. i wrote the following but it returns.."512BXIPI_BP6_USD: operator invalid"... help will be appreciated..

    keep year B-EY
    foreach v of varlist B-EY {
    local x: variable label `v'
    local nz = substr(`x', 1,3)
    rename `v' y`nz'
    }

  • #2
    At least one typo spotted (colored red below):

    Code:
    keep year B-EY
    foreach v of varlist B-EY {
    local x: variable label `v'
    local nz = substr("`x'", 1,3)
    rename `v' y`nz'
    }
    Roman

    Comment

    Working...
    X