Announcement

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

  • Differentiating between extended missings in -misstable- or -missings report-

    Dear Statalist,

    I am struggling to create a single table of missing values for all variables, that differentiates between each type of extended missing (.a, .b, etc). neither -misstable summarize- nor -missings report- seem to have this functionlaity (though both can differentiate system missings (.) from _all_ extended misssings (total of .a, .b, etc). The user-written -misschk- seems to have the required option, but -misschk- is no longer possible to install, it seems.

    Here is the result I want (with or without additional columns, preferable listing all variables regardless of the presence of missings)

    Code:
              .a     .b
    ------------------------------------
    var1       0     32
    var2      12     64
    ...
    Many thanks for your advice!

  • #2
    I don't know anything about misschk. I know more about missings, as I wrote it.

    missings is also user-written (community-contributed is now the recommended jargon). In an up-to-date Stata, search missings, sj will find details; otherwise you may need the more unpredictable

    Code:
    . search dm0085, entry
    
    Search of official help files, FAQs, Examples, and Stata Journals
    
    SJ-20-4 dm0085_2  . . . . . . . . . . . . . . . . Software update for missings
            (help missings if installed)  . . . . . . . . . . . . . . .  N. J. Cox
            Q4/20   SJ 20(4):1028--1030
            sorting has been extended for missings report
    
    SJ-17-3 dm0085_1  . . . . . . . . . . . . . . . . Software update for missings
            (help missings if installed)  . . . . . . . . . . . . . . .  N. J. Cox
            Q3/17   SJ 17(3):779
            identify() and sort options have been added
    
    SJ-15-4 dm0085  Speaking Stata: A set of utilities for managing missing values
            (help missings if installed)  . . . . . . . . . . . . . . .  N. J. Cox
            Q4/15   SJ 15(4):1174--1185
            provides command, missings, as a replacement for, and extension
            of, previous commands nmissing and dropmiss
    This problem exposes something that missings cannot do, but makes perfect sense, so I will look into extending the code. Meanwhile here are some experiments with countvalues from SSC, discussed at https://www.statalist.org/forums/for...lable-from-ssc

    Code:
    clear 
    input testvar1 
    1      
    2
    3
    .
    .a
    .b
    .z 
    end
    
    gen testvar2 = testvar1 
    
    gen testvar3 = cond(_n == _N, 1.23, .z)
    
    list
    Here is the test dataset.

    Code:
    . list 
    
         +--------------------------------+
         | testvar1   testvar2   testvar3 |
         |--------------------------------|
      1. |        1          1         .z |
      2. |        2          2         .z |
      3. |        3          3         .z |
      4. |        .          .         .z |
      5. |       .a         .a         .z |
         |--------------------------------|
      6. |       .b         .b         .z |
      7. |       .z         .z       1.23 |
         +--------------------------------+

    What is easy is when you know what you are looking for:

    Code:
    countvalues testvar*, values(.a .b .z)
    
      +-------------------------+
      |     name   .a   .b   .z |
      |-------------------------|
      | testvar1    1    1    1 |
      | testvar2    1    1    1 |
      | testvar3    0    0    6 |
      +-------------------------+
    But a fair task is for Stata to work out which missing values exist anywhere in a bunch of variables. Here is my best stab at that so far.


    Code:
    foreach v of var testvar* {
        levelsof `v' if missing(`v'), missing clean local(this)
        local levels `levels' `this'
    }
    
    local levels : list uniq levels 
    local levels : list sort levels 
    
    countvalues testvar*, values(`levels')
    .
    .
    with results

    Code:
     
      +-----------------------------+
      |     name   .   .a   .b   .z |
      |-----------------------------|
      | testvar1   1    1    1    1 |
      | testvar2   1    1    1    1 |
      | testvar3   0    0    0    6 |
      +-----------------------------+

    Comment


    • #3
      Thank you!

      I was not aware of countvalues, and

      Code:
      countvalues, values(. .a .b)
      gives me exactly what I need. And it would be great if an updated version of -missings- incorporates this possibility!

      Comment


      • #4
        https://www.statalist.org/forums/for...updated-on-ssc advertises an update to missings on SSC. Thanks for the stimulating question!
        Last edited by Nick Cox; 28 Jan 2023, 10:56.

        Comment

        Working...
        X