Announcement

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

  • Help with merging datasets using firm_id and DateStartRole

    Dear Statalist members,

    I hope you're all doing well.

    I'm currently working with two datasets that I need to merge using firm_id and DateStartRole as the key variables. However, I’ve encountered a mismatch in the format of the DateStartRole variable:
    • In Dataset 1, DateStartRole is already a numerical Stata date.
    • In Dataset 2, DateStartRole is a string in the format "1/1/2002".
    Before performing the merge, I would like to convert the string version of DateStartRole in Dataset 2 into a numerical Stata date so that the merge can proceed correctly.

    Could someone please advise on the best way to convert the string into a numerical Stata date?

  • #2
    given your example, it is not possible to tell whether your data are in day/month/year or month/day/year format it is not possible to give conclusive advice but you probably want one of:
    Code:
    gen DateStartRole2=daily(DateStartRole,"MDY")
    or,
    gen DateStartRole2=daily(DateStartRole,"DMY")
    you probably can tell by looking at other examples which you want

    then you need to either drop the string version and rename (see help rename) the new version of the variable or rename both if you want to retain the string version; then you can merge (here making assumptions about what you mean by "numerical Stata date");

    Comment


    • #3
      Thanks alot proffesor Rich it works

      Comment

      Working...
      X