Announcement

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

  • How to list missing values for each observation

    Hi everyone,

    I would need to create a list including all observations and only missing values (which I have indicated with .a) for all variables.

    This is because in the context of a multicentric study I need to send specific requests to different sites. They will check for each ID the corresponding missing data on the questionnaires.

    I have found very nice commands to describe the missing data pattern but not how to simply list observations and corresponding missing values in the whole dataset (that is very huge).

    Do you have any suggestion?

    Thank you very much indeed for your help



    Last edited by Diego Quattrone; 02 Jul 2016, 07:58.

  • #2
    Diego:
    welcome to the list.
    You may want to try something along the following lines:
    Code:
    foreach var of varlist var_1-var_n  {
    bysort idcenter: list idcenter idpatient if `var'==".a"
    }
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hello Diego,

      Welcome to the Stata Forum.

      You may try this:

      Code:
      . use "C:\Program Files (x86)\Stata14\ado\base\a\auto.dta", clear
      (1978 Automobile Data)
      
       
      . tab rep78, missing
      
           Repair |
      Record 1978 |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                1 |          2        2.70        2.70
                2 |          8       10.81       13.51
                3 |         30       40.54       54.05
                4 |         18       24.32       78.38
                5 |         11       14.86       93.24
                . |          5        6.76      100.00
      ------------+-----------------------------------
            Total |         74      100.00
      
      . replace rep78 = .a in 3
      (1 real change made, 1 to missing)
      
      . replace rep78 = .b in 7
      (1 real change made, 1 to missing)
      
      . tab rep78, missing
      
           Repair |
      Record 1978 |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                1 |          2        2.70        2.70
                2 |          8       10.81       13.51
                3 |         30       40.54       54.05
                4 |         18       24.32       78.38
                5 |         11       14.86       93.24
                . |          3        4.05       97.30
               .a |          1        1.35       98.65
               .b |          1        1.35      100.00
      ------------+-----------------------------------
            Total |         74      100.00
      
       
      
      . list rep78 if missing(rep78)
      
           +-------+
           | rep78 |
           |-------|
        3. |    .a |
        7. |    .b |
       45. |     . |
       51. |     . |
       64. |     . |
           +-------+

      Best,

      Marcos
      Best regards,

      Marcos

      Comment


      • #4
        See also missings (SSC, and now SJ):

        http://www.statalist.org/forums/foru...aging-missings

        http://www.stata-journal.com/article...article=dm0085

        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . missings list
        
        Checking missings in all variables:
        5 observations with missing values
        
             +-------+
             | rep78 |
             |-------|
          3. |     . |
          7. |     . |
         45. |     . |
         51. |     . |
         64. |     . |
             +-------+
        
        . replace mpg = . in   42
        (1 real change made, 1 to missing)
        
        . missings list
        
        Checking missings in all variables:
        6 observations with missing values
        
             +-------------+
             | mpg   rep78 |
             |-------------|
          3. |  22       . |
          7. |  26       . |
         42. |  .a       3 |
         45. |  26       . |
         51. |  19       . |
             |-------------|
         64. |  14       . |
             +-------------+

        Comment


        • #5
          You're not very specific, but perhaps you could try something like the following.
          Code:
          foreach var of varlist _all {
              if inlist("`var'", "ID", "site") continue
              list ID `var' if missing(`var')
          }
          From what you've said, the output is liable to be pretty voluminous. You could try to make it a little more compact with something like the following.
          Code:
          foreach var of varlist _all {
              if inlist("`var'", "ID", "site") continue
              local varlist `varlist' `var'
          }
          
          quietly generate str missings = ""
          foreach var of varlist `varlist' {
              quietly replace missings = missings + " `var'" if missing(`var')
          }
          
          sort site ID
          list ID missings if !missing(missings), noobs sepby(site)
          Last edited by Joseph Coveney; 02 Jul 2016, 09:28.

          Comment

          Working...
          X