Announcement

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

  • Decoding

    Hello,

    I am trying to merge (1:1) two data sets by a common variable: a 10-digit UserID. Unfortunately, this variable has different Types and Formats in my datasets: it is Type = double and Format = %10.0g in the one and Type = str10 and Format = %10s in the other. All else equal I prefer converting the numeric version to the string rather than the other way around. So I tried

    decode UserID, generate(UserID_str)

    and received the following message:

    UserID not labeled
    r(182);

    I am not a skilled Stata user, but judging from the error message I feel that 'decode' could be specifically suited for situations when one wants to create a new string variable based on the numeric values in the original. So not the solution I am looking for. Attempts to use 'recast str10 UserID' and 'g UserID_str = string(UserID, "%010.0f"' were equally underwhelming. Could someone please help me with this?

    Many thanks in advance.

    Sincerely,

    Gayaneh

  • #2
    Hi Gayaneh,

    I think the solution Nick Cox provided in this post from 2019 will solve your problem, too.
    Devra Golbe
    Professor Emerita, Dept. of Economics
    Hunter College, CUNY

    Comment


    • #3
      It worked. Thank you!

      Comment

      Working...
      X