Announcement

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

  • Command skips several rows

    Dear community,

    I have a dataset with 38 participants that I want to prepare for survival analysis. My code is:

    Code:
    *** format entry and exit dates and times adequately
    gen double entrydatetime= Clock(entrydate+" "+entrytime, "DMYhm")
    gen double exitdatetime10qPCR= Clock(exitdate10qPCR+" "+exittime10qPCR, "DMYhm")
    format entrydatetime %tcDD/NN/CCYY_HH:MM
    format exitdatetime10qPCR %tcDD/NN/CCYY_HH:MM
    destring censored10qPCR, replace
    *** prepare data for suvival analysis
    stset exitdatetime10qPCR, enter(entrydatetime) origin(entrydatetime) failure(censored10qPCR)
    gen diff=exitdatetime10qPCR-entrydatetime
    sts list
    Yesterday it worked just fine, but today the code does not generate all necessary values. On the contrary, today I see this:

    Code:
    . gen double entrydatetime= Clock(entrydate+" "+entrytime, "DMYhm")
    (21 missing values generated)
    
    . 
    . gen double exitdatetime10qPCR= Clock(exitdate10qPCR+" "+exittime10qPCR, "DMYhm")
    (38 missing values generated)
    When browsing my data, I only see entrydatetime for 17 out of 38 missing participants, for all other participants the value displayed is ".", and exitdatetime10qPCR is "." for all 38 participants. This leads to all event times missing in stset and no observations in sts list.
    How can I fix this?

    Thank You,
    Dorothea

  • #2
    The code looks fine and will work if the data are appropriate for it. The problem is almost certainly in your data. Perhaps some of the values of these string-date variables are not in the format you have specified, for example. Anyway, to get more than vague guidance you need to show some example data that reproduces these problems. Please post back to do that, and use the -dataex- command for the purpose.

    If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Dear Clyde,

      Thank You for the explanation. I feared learning Stata (or any other software) for a long time but this forum makes it fun.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str10 entrydate str5 entrytime str10 exitdate10qPCR str8 exittime10qPCR
      " 6/19/2019" "18:45" " 6/22/2019" "12:08:59"
      " 7/10/2019" "17:20" " 7/11/2019" "03:51:00"
      " 7/30/2019" "12:24" " 7/30/2019" "23:27:00"
      " 7/30/2019" "14:45" "  8/6/2019" "15:51:00"
      " 8/21/2019" "16:38" " 8/28/2019" "14:13:00"
      "  9/4/2019" "13:15" "  9/9/2019" "17:00:00"
      "10/18/2019" " 8:47" "10/18/2019" "19:50:00"
      "10/29/2019" "16:11" " 11/5/2019" "16:28:00"
      " 11/5/2019" "14:50" "11/12/2019" "15:14:00"
      " 12/4/2019" "14:15" " 12/5/2019" "09:40:59"
      end
      This is an excerpt of my data, I hope it helps to answer my question.

      Comment


      • #4
        Your date format is MDY (month, date, year) and not DMY (date, month, year).

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str10 entrydate str5 entrytime str10 exitdate10qPCR str8 exittime10qPCR
        " 6/19/2019" "18:45" " 6/22/2019" "12:08:59"
        " 7/10/2019" "17:20" " 7/11/2019" "03:51:00"
        " 7/30/2019" "12:24" " 7/30/2019" "23:27:00"
        " 7/30/2019" "14:45" "  8/6/2019" "15:51:00"
        " 8/21/2019" "16:38" " 8/28/2019" "14:13:00"
        "  9/4/2019" "13:15" "  9/9/2019" "17:00:00"
        "10/18/2019" " 8:47" "10/18/2019" "19:50:00"
        "10/29/2019" "16:11" " 11/5/2019" "16:28:00"
        " 11/5/2019" "14:50" "11/12/2019" "15:14:00"
        " 12/4/2019" "14:15" " 12/5/2019" "09:40:59"
        end
        
        g double wanted= Clock(entrydate+" "+entrytime, "MDYhm")
        format wanted %tcDD/NN/CCYY_HH:MM
        Res.:

        Code:
        . l, sep(0)
        
             +------------------------------------------------------------------+
             |  entrydate   entryt~e   exitdate~R   exitti~R             wanted |
             |------------------------------------------------------------------|
          1. |  6/19/2019      18:45    6/22/2019   12:08:59   19/06/2019 18:45 |
          2. |  7/10/2019      17:20    7/11/2019   03:51:00   10/07/2019 17:20 |
          3. |  7/30/2019      12:24    7/30/2019   23:27:00   30/07/2019 12:24 |
          4. |  7/30/2019      14:45     8/6/2019   15:51:00   30/07/2019 14:45 |
          5. |  8/21/2019      16:38    8/28/2019   14:13:00   21/08/2019 16:38 |
          6. |   9/4/2019      13:15     9/9/2019   17:00:00   04/09/2019 13:15 |
          7. | 10/18/2019       8:47   10/18/2019   19:50:00   18/10/2019 08:47 |
          8. | 10/29/2019      16:11    11/5/2019   16:28:00   29/10/2019 16:11 |
          9. |  11/5/2019      14:50   11/12/2019   15:14:00   05/11/2019 14:50 |
         10. |  12/4/2019      14:15    12/5/2019   09:40:59   04/12/2019 14:15 |
             +------------------------------------------------------------------+
        Last edited by Andrew Musau; 07 Oct 2022, 03:41.

        Comment


        • #5
          Code:
          gen double entrydatetime= Clock(entrydate+" "+entrytime, "MDYhm")
          gen double exitdatetime10qPCR= Clock(exitdate10qPCR+" "+exittime10qPCR, "MDYhms")
          format entrydatetime %tcDD/NN/CCYY_HH:MM
          format exitdatetime10qPCR %tcDD/NN/CCYY_HH:MM
          destring censored10qPCR, replace
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str10 entrydate str5 entrytime double entrydatetime str10 exitdate10qPCR str8 exittime10qPCR double exitdatetime10qPCR
          " 6/19/2019" "18:45" 1876589127000 " 6/22/2019" "12:08:59" 1876824566000
          " 7/10/2019" "17:20" 1878398427000 " 7/11/2019" "03:51:00" 1878436287000
          " 7/30/2019" "12:24" 1880108667000 " 7/30/2019" "23:27:00" 1880148447000
          " 7/30/2019" "14:45" 1880117127000 "  8/6/2019" "15:51:00" 1880725887000
          " 8/21/2019" "16:38" 1882024707000 " 8/28/2019" "14:13:00" 1882620807000
          "  9/4/2019" "13:15" 1883222127000 "  9/9/2019" "17:00:00" 1883667627000
          "10/18/2019" " 8:47" 1887007647000 "10/18/2019" "19:50:00" 1887047427000
          "10/29/2019" "16:11" 1887984687000 " 11/5/2019" "16:28:00" 1888590507000
          " 11/5/2019" "14:50" 1888584627000 "11/12/2019" "15:14:00" 1889190867000
          " 12/4/2019" "14:15" 1891088127000 " 12/5/2019" "09:40:59" 1891158086000
          end
          format %tcDD/NN/CCYY_HH:MM entrydatetime
          format %tcDD/NN/CCYY_HH:MM exitdatetime10qPCR
          Issue solved, thank You once again!

          Comment

          Working...
          X