Announcement

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

  • #16
    Sorry about the mangled script in the previous.

    Code:
    log using choonjo_problems.log
    
    set more off
    
    display "Stata " c(stata_version)
    foreach cmd in findname missings {
        which `cmd'
    }
    
    * 2. missings breakdown: error r(3000) when missing values occur only in strings.
    *    Numeric variables can be present, provided none of them has a missing value.
    clear
    input byte id str1 s
    1 "a"
    2 ""
    end
    capture noisily missings breakdown
    local bd_rc = _rc
    display "missings breakdown: rc=`bd_rc'"
    assert `bd_rc' == 3000
    * capture noisily displays the expected error and lets the remaining examples run.
    * In actual checks, do not ignore an error and interpret it as "no missing values".
    
    * 3. Recommended: findname for a variable list; missings report for counts.
    *    missing() detects numeric . and .a-.z, and the empty string "".
    findname _all, any(missing(@))
    local mvars "`r(varlist)'"
    display "Variables with missing values: `mvars'"
    assert "`mvars'" == "s"
    missings report
    assert "`r(varlist)'" == "s"
    
    log close

    Comment


    • #17
      The bug in missings has been fixed. A Software Update will be submitted to the Stata Journal. Thanks again to Choonjoo Lee for reporting this bug.

      If missing values occurred only in string variables, then the count of numeric levels that are missing should be set to 0 as in the command

      Code:
      else local nlevels = 0
      added to the block cited here.

      Code:
      quietly if `numhere' | "`seeallzeros'" != "" { 
                  if "`sysmiss'" != "" local levels . 
      
                  else {
                      foreach v of local misslist {
                          levelsof `v' if missing(`v') & `touse', missing clean local(this) 
                          local levels `levels'  `this' 
                      } 
                      local levels : list uniq levels 
                      local levels : list sort levels 
                      
                      if "`levels'" == "" & "`seeallzeros'" != "" local levels . 
                  } 
      
                  local nlevels : list sizeof levels
      } 
      else local nlevels = 0
      Last edited by Nick Cox; 11 Oct 2026, 15:54.

      Comment


      • #18
        Thank you, Nick. I'm glad my observation was helpful, even if I stumbled upon it almost by accident!

        My background is not in software development, and I've learned Stata programming largely through trial and error. Handling missing values and variables was one of the many challenges I encountered along the way.

        I'm pleased that sharing one of those experiences helped identify a bug. Thanks for fixing it!

        Comment


        • #19
          Thank you again for the fix. Could you also check the following example against your revised version? With sysmiss, I would expect both commands to report one missing value. In the currently available version, missings report gives 1, but missings breakdown shows 3 under “# missing” and 1 under “.”. This may be a separate issue in how the total is calculated.

          Code:
          clear
          input double x
          .
          .a
          .z
          1
          end
          
          * Both commands should count only the single system missing value (.).
          missings report x, sysmiss
          missings breakdown x, sysmiss
          Thanks a lot!

          Comment


          • #20
            Correct again and many thanks. I will add the fix to the code.

            Comment


            • #21
              As an update to #15 the files for missings are now available given the update of Stata on 14 October.

              The command name missings for a community-contributed command is, I readily admit, unfortunate as well as defensible. Unfortunate insofar as search for it finds too much. The otherwise unpredictable search term dm0085 is recommended.

              Code:
              . search dm0085, entry
              
              Search of official help files, FAQs, Examples, and Stata Journals
              
              SJ-26-3 dm0085_4  . . . . . . . . . . . . . . . . Software update for missings
                      (help missings if installed)  . . . . . . . . . . . . . . .  N. J. Cox
                      Q3/26   SJ 26(3):537
                      new option added
              
              SJ-23-2 dm0085_3  . . . . . . . . . . . . . . . . Software update for missings
                      (help missings if installed)  . . . . . . . . . . . . . . .  N. J. Cox
                      Q2/23   SJ 23(2):595--596
                      most important change is the addition of subcommand breakdown
              
              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
              Code:
              
              


              This update does not include the latest fixes prompted by bug reports from Choonjoo Lee -- which, as said, will be submitted for publication in the Stata Journal in due course. I will ask Kit Baum to update the version on SSC.

              Comment


              • #22
                ssc describe mdesc // mdesc -- Displays the number and proportion of missing values for each variable in varlist.

                Comment


                • #23
                  The main question in this thread as started by Chen Samulsion is to see just lists of variable names (varlists) for those variables with missing values. (That doesn't stop people asking or answering with broader or related topics.)

                  mdesc was mentioned briefly in #8 . It can certainly be used to show such varlists in this manner. First, a reminder by default output that rep78 is the only variable in the auto data with missing values. Then, how to see that name as a varlist without other output. That is just two steps. Other commands can do it in one step, but anyone who finds mdesc both simple and useful has excellent reason to be appreciative.

                  Code:
                  . sysuse auto, clear
                  (1978 automobile data)
                  
                  . mdesc
                  
                      Variable    |     Missing          Total     Percent Missing
                  ----------------+-----------------------------------------------
                             make |           0             74           0.00
                            price |           0             74           0.00
                              mpg |           0             74           0.00
                            rep78 |           5             74           6.76
                         headroom |           0             74           0.00
                            trunk |           0             74           0.00
                           weight |           0             74           0.00
                           length |           0             74           0.00
                             turn |           0             74           0.00
                     displacement |           0             74           0.00
                       gear_ratio |           0             74           0.00
                          foreign |           0             74           0.00
                  ----------------+-----------------------------------------------
                  
                  
                  . qui mdesc
                  
                  . di "`r(miss_vars)'"
                  rep78

                  Comment


                  • #24
                    As promised in #21 missings has been updated on SSC.

                    https://www.statalist.org/forums/for...lable-from-ssc

                    Comment

                    Working...
                    X