Announcement

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

  • Require created variable to match variable format

    Recently I've had a recurring problem when manipulating ID variables in a dataset. The problem occurs when I generate a clone of a variable, the new variable does not retain the formatting of the original. For example:

    Code:
    sysuse auto
    gen id = string(price) + string(length) + string(weight)
    destring id, replace
    gen newvar = id
    assert id == newvar
    Here assert returns an error, presumably because id is stored as %10.0g (double) while newvar is %9.0g (float).

    Is there a way that I can require newvar to conform to the formatting of id, without hard-coding the format?

    (Running STATA 14 64-bit on Win 7)

    Thanks,

    Mike

  • #2
    Code:
     
    help clonevar

    Comment


    • #3
      Asked & answered. Thanks!

      Comment

      Working...
      X