Announcement

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

  • #16
    You didn't answer the question in #14.

    We need to see data for which missing values are generated. The recipe looks good.

    Comment


    • #17
      ans of #14, I am using stata 14.

      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str9 n_dob str5 n_tob str9 n_doa str5 n_toa
      "01-Mar-20" "20:45" "01-Mar-20" "20:55"
      "14-Feb-20" "21:47" "15-Feb-20" "01:20"
      "14-Dec-19" "21:12" "31-Dec-19" "14:00"
      "14-Jan-20" "19:42" "21-Jan-20" "03:15"
      "12-Mar-20" "09:03" "18-Mar-20" "21:35"
      "28-Feb-20" "20:30" "28-Feb-20" "23:40"
      "14-Feb-20" "15:06" "14-Feb-20" "16:20"
      "26-Jan-20" "01:24" "26-Jan-20" "02:45"
      "31-Dec-19" "20:30" "04-Jan-20" "19:20"
      "15-Feb-20" "10:02" "15-Feb-20" "11:45"


      while using @ command a and b values are generated easily but after giving command

      gen double age = (clock(a,"DMYhm") - clock(b,"DMYhm")) / (3600000*24) it gives out 10 values missing generated

      Comment


      • #18
        #17 suggests two-digit years so code in #2 must be modified,
        Code:
        egen a = concat(doa toa), p(" ")
        egen b = concat(dob tob), p(" ")
        
        gen double age = (clock(a,"DM20Yhm") - clock(b,"DM20Yhm")) / (3600000*24)

        Comment


        • #19
          This is the same mistake as explained in #12 here and in your other thread https://www.statalist.org/forums/for...g-into-numeric -- see especially daniel klein 's post.

          The century can't be left tacit, obvious though it is to you that you have dates in this century.

          The code in #17 won't run without extra commands, but this is a self-contained script with the results.

          Code:
          clear
          input str9 n_dob str5 n_tob str9 n_doa str5 n_toa
          "01-Mar-20" "20:45" "01-Mar-20" "20:55"
          "14-Feb-20" "21:47" "15-Feb-20" "01:20"
          "14-Dec-19" "21:12" "31-Dec-19" "14:00"
          "14-Jan-20" "19:42" "21-Jan-20" "03:15"
          "12-Mar-20" "09:03" "18-Mar-20" "21:35"
          "28-Feb-20" "20:30" "28-Feb-20" "23:40"
          "14-Feb-20" "15:06" "14-Feb-20" "16:20"
          "26-Jan-20" "01:24" "26-Jan-20" "02:45"
          "31-Dec-19" "20:30" "04-Jan-20" "19:20"
          "15-Feb-20" "10:02" "15-Feb-20" "11:45"
          end
          
          gen double age = (clock(n_doa + " " + n_toa,"DM20Yhm") - clock(n_dob + " " + n_tob,"DM20Yhm")) / (3600000*24)
          
          list
          
               +---------------------------------------------------+
               |     n_dob   n_tob       n_doa   n_toa         age |
               |---------------------------------------------------|
            1. | 01-Mar-20   20:45   01-Mar-20   20:55   .00694444 |
            2. | 14-Feb-20   21:47   15-Feb-20   01:20   .14791667 |
            3. | 14-Dec-19   21:12   31-Dec-19   14:00        16.7 |
            4. | 14-Jan-20   19:42   21-Jan-20   03:15   6.3145833 |
            5. | 12-Mar-20   09:03   18-Mar-20   21:35   6.5222222 |
               |---------------------------------------------------|
            6. | 28-Feb-20   20:30   28-Feb-20   23:40   .13194444 |
            7. | 14-Feb-20   15:06   14-Feb-20   16:20   .05138889 |
            8. | 26-Jan-20   01:24   26-Jan-20   02:45      .05625 |
            9. | 31-Dec-19   20:30   04-Jan-20   19:20   3.9513889 |
           10. | 15-Feb-20   10:02   15-Feb-20   11:45   .07152778 |
               +---------------------------------------------------+
          Thanks for the information that you are using Stata version 14. The FAQ Advice asks that you tell us about using an up-to-date version.

          11. What should I say about the version of Stata I use?



          The current version of Stata is 17. Please specify if you are using an earlier version; otherwise, the answer to your question may refer to commands or features unavailable to you. Moreover, as bug fixes and new features are issued frequently by StataCorp, make sure that you update your Stata before posting a query, as your problem may already have been solved.
          The problem that

          otherwise, the answer to your question may refer to commands or features unavailable to you
          has already bitten you, as the advice in #7 and #9 to use clockdiff_frac() presumably triggered an error message, although you didn't report that until #13. So, henceforth please start all threads with the information "I am using Stata 14".
          Last edited by Nick Cox; 08 Apr 2022, 05:01.

          Comment


          • #20
            thanks it worked
            Last edited by Pratibha Singh; 08 Apr 2022, 04:39.

            Comment

            Working...
            X