Announcement

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

  • Ambiguous abbreviation inside the loop

    Hi all!

    I have silly problem and I hope it's not to stupid to ask you guys about it.

    I imported a data file with information about income in various metropolitans area. When I import the data the variables for each year named like this: v3, v4,...,v38.
    I want to rename them quickly by a loop, so I tried this:

    Click image for larger version

Name:	image.png
Views:	1
Size:	73.4 KB
ID:	1727013


    Can someone tell me why doesn't it work and what should I do?

    Sorry for the basic question again, and SHANA TOVA!

    FitzGerald

  • #2
    You have a parallel renaming scheme, but this double loop will work on all combos. So, in the first loop, it rename "v3" into "personalincome1985", then looping to next j, it wants to "rename v3 personalincome1986". Because there is no v3 anymore (got renamed), and v30-v38 became the next candidate, since there are multiple of v3*, it became ambiguous.

    Try this instead, just one rename for each variable, instead of 36 renaming to the same variable:

    Code:
    forvalues i = 3(1)38{
    rename v`i' personalincome`=1982+`i''
    }
    Last edited by Ken Chui; 13 Sep 2023, 09:30.

    Comment


    • #3
      Code:
      rename v# personalincome#, renumber(1982)
      should work.

      Comment


      • #4
        Thank you folks! both of the ways worked out

        Comment

        Working...
        X