Announcement

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

  • Convert from double to string to append multiple datasets

    Dear Statalisters,

    When I try to append multiple datasets, I encounter a problem with different data types. Overall, I convert all variables (type mismatch) into "str". However, it does not work for a variable containing information about time, for example: 09:45. This variable is in "double" in some datasets, "int" in some datasets, and "str" in some others.
    The error is: ... cannot be converted reversibly; no replace
    I have read this post: https://www.statalist.org/forums/for...uble-to-string, but I don't know how to do in my case.
    I would appreciate any advice on my case.

    Thanks

  • #2
    EDITED: Time variables should be stored as double. Can you give a dataex example of those stored as int and str formats? I think the best approach is to convert each to double in the respective datasets before merging. However, you can convert a time variable (SIF values) to string as below:

    Code:
    gen wanted= string(timevar, "%20.0f")
    Last edited by Andrew Musau; 27 Jan 2024, 11:11.

    Comment


    • #3
      It works. Thanks alot, Andrew.

      Comment

      Working...
      X