Announcement

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

  • No observation error - all data filtered

    My problem with Stata 15.0 concerns the r(2000) error: no observations. You have requested some statistical calculation and there are no observations on which to perform it. Perhaps you specified if or in and inadvertently filtered all the data.

    This makes sense because when I manually check my data I can see that my code has indeed filtered all of the data. However as I am using Stata to clean data and check for errors this is actually a good thing (it means the data that piece of code was checking is clean and free of errors). So how do I run this code but make it so that if the code does filter all the data it just carries on to the next chunk of code?

    The code I am using is:

    Code:
    putdocx paragraph
    putdocx text ("ILI 3 date of onset is not between the baseline date and the 30th April 2018")
    putdocx table TRIALNAME = data(StudySubjectID VISDAT_E1_C1 ILISTDAT_E7_C17_3) if ///
    ILISTDAT_E7_C17_3 > td(30apr2018) & ILISTDAT_E7_C17_3 !=.
    I have also tried using:

    Code:
    if !_rc {
    putdocx paragraph
    putdocx text ("ILI 3 date of onset is not between the baseline date and the 30th April 2018")
    putdocx table TRIALNAME = data(StudySubjectID VISDAT_E1_C1 ILISTDAT_E7_C17_3) if ///
    ILISTDAT_E7_C17_3 > td(30apr2018) & ILISTDAT_E7_C17_3 !=.
    }
    The latter prevented the error from occurring, but when I entered dummy data of a date that the code should pull out (05/05/2018) it didn’t pull this out.

    Example data (this is made up data for confidentiality reasons but this reflects the type of data I am working with) (I read about dataex but it was not clear from the guidance on how to implement this in a forum pot, I hope what I have done below is satisfactory, if not the please let me know how to amend what I have done and I will do so):

    Code:
     
    StudySubjectID VISDAT_E1_C1 ILISTDAT_E7_C17_3
    100 06/10/2017 15/02/2018
    101 06/10/2017
    102 10/10/2017 22/02/2018
    103 21/10/2017 03/03/2018
    104 23/10/2017 12/12/2017
    105 30/10/2017
    106 30/10/2017
    107 31/10/2017 05/01/2018
    108 01/11/2017
    109 01/11/2017
    110 02/11/2017 06/04/2018
    110 02/11/2017 23/03/2018
    110 02/11/2017 21/12/2017
    110 02/11/2017
    110 02/11/2017
    110 02/11/2017
    110 03/11/2017 15/01/2018
    110 03/11/2017
    110 03/11/2017
    110 04/11/2017 29/04/2018
    Thank you in advance for any advice.

    Best wishes,
    Jenna

  • #2
    You show three variables there. You need to show the results of

    Code:
    describe  StudySubjectID    VISDAT_E1_C1    ILISTDAT_E7_C17_3
    so that we can see storage types and display formats. (That is what dataex does.)

    I've never used putdocx so I may not reply, but I think people who do use it need this information. My wild guess is that your dates are still string variables.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      You show three variables there. You need to show the results of

      Code:
      describe StudySubjectID VISDAT_E1_C1 ILISTDAT_E7_C17_3
      so that we can see storage types and display formats. (That is what dataex does.)

      I've never used putdocx so I may not reply, but I think people who do use it need this information. My wild guess is that your dates are still string variables.
      Thank you for your advice Nick. I have checked at the dates are in integer format:


      StudySubjectID str7 %9s
      VISDAT_E1_C1 int %td
      ILISTDAT_E7_C~3 int %td

      Comment


      • #4
        OK. So I note that in your example the dates after 30 April 2018 do not occur for the third variable.

        Comment


        • #5
          Correct, which means the data is in fact clean. So ideally Stata would just skip this and move on rather than sending out an error message. As I am working with a large dataset I'd like to be able to clean that data using a Stata program rather than manually checking the data.

          Comment


          • #6
            I managed to fix this issue by using "capture", see amended code:

            Code:
            capture quietly {
            putdocx paragraph
            putdocx text ("ILI 3 date of onset is not between the baseline date and the 30th April 2018")
            putdocx table TRIALNAME = data(StudySubjectID VISDAT_E1_C1 ILISTDAT_E7_C17_3) if ///
            ILISTDAT_E7_C17_3 > td(30apr2018) & ILISTDAT_E7_C17_3 !=.
            }
            Hope this can help someone else out too!

            Comment

            Working...
            X