Announcement

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

  • Renaming Variables

    I am using STATA 15. I have a large data set with multiple columns and rows. I am interested in two variables , var1 and var2, each of which have multiple entries. I would like to rename var1 with the same name as var2. However, when I use the code rename var1 var2, I receive the error message variable var2 already defined. When I use the code rename (var1 var2) (var3 var3), I get the following error message: 1 new name specified repeatedly in newname. You requested the name var3 be assigned to 2 existing variables: var1 and var2.

    How can I make the two columns of data with the two different variable names both have the same name?

    Thank you.

  • #2
    Originally posted by Chris Ana View Post
    How can I make the two columns of data with the two different variable names both have the same name?
    You cannot. Why do you think you want to?

    Best
    Daniel

    Comment


    • #3
      I have millions of unique IDs in the set of data. For one group of unique IDs, we used var1 and var2 is listed as missing. For the second half of unique IDs, we used var2 and var1 is missing. Both variables are in the data set, but they should be joined together as one variable so we can perform our analysis on all of the IDs simultaneously.

      For example,
      ID var1 var2
      1 0 .
      2 1 .
      3 1 .
      4 0 .
      5 . 1
      6 . 0
      7 . 1
      8 . 1
      Thank you.

      Comment


      • #4
        Ok, but renaming isn't the solution to that. Try


        Code:
        replace var1  = var2 if missing(var1)
        count if missing(var1)
        The result of the count should be zero. If so, then


        Code:
        drop var2 
        rename var1 id
        or some other more informative name.

        Comment

        Working...
        X