Announcement

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

  • IDs split in two columns

    I am using a dataset that, for some reason, has a column called id_b, and another called id_c. Every row with a value in id_b has nothing in id_c, and vice versa. I simply want to combine these columns into a column named id.

    I have attempted to use egen id = rowmax (id_b id_c), but whilst the id_b and id_c columns are both long data, this produces a column which is a float, and when I convert this to long, these are rounding issues as the IDs are 8 or 9 numbers long.

  • #2
    -egen- allows you to specify the type you want the new variable to be so you could just insert "long" or "double" after -egen- in your command; or if you wanted to not make a new variable you could use -replace- to
    Code:
    replace id_b=id_c if missing(id_b)
    and there are other options; but be sure to read
    Code:
    h egen
    note that since you did not supply a data example using -dataex-, there might be errors or typos above

    Comment


    • #3
      It's a good idea to hold ID variables as string rather than numeric. See

      Code:
      help tostring
      (That brings up the help entry for destring.)
      Devra Golbe
      Professor Emerita, Dept. of Economics
      Hunter College, CUNY

      Comment


      • #4
        Originally posted by Rich Goldstein View Post
        -egen- allows you to specify the type you want the new variable to be so you could just insert "long" or "double" after -egen- in your command; or if you wanted to not make a new variable you could use -replace- to
        Code:
        replace id_b=id_c if missing(id_b)
        and there are other options; but be sure to read
        Code:
        h egen
        note that since you did not supply a data example using -dataex-, there might be errors or typos above
        Thank you Rich - simply adding long to the command did exactly what I needed!

        Comment

        Working...
        X