3

I know a way of finding and identifying missing values for a particular variable.

For the variable avedmajor, I could do

tab avedmajor, m

Then,

gen avedmajormissing=0

replace avedmajormissing=1 if avedmajor==.

But how to see if my dataset has missing values in any of the variables without going through each one of them?

Thanks.

2
  • 1
    Your second example would be better as gen avedmajormissing = missing(avedmajor). Note also that your syntax does nothing about extended missing values and is only for numeric variables. Commented Jul 9, 2014 at 17:34
  • I assume your code includes both numeric and string values? Commented Jul 9, 2014 at 17:38

4 Answers 4

5

I'd add mdesc command to proposed solutions. According to description mdesc:

Produces a table with the number of missing values, total number of cases, and percent missing for each variable in varlist. mdesc works with both numeric and character variables.

So advantage to misstable solution is that it works with both numeric and string variables in one go.

sysuse auto
mdesc

Gives a nice overview of missings:

    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
----------------+-----------------------------------------------
Sign up to request clarification or add additional context in comments.

2 Comments

If interested, install by ssc inst mdesc in Stata, not via your browser.
Much better... does strings and numeric in a super clean format, recommend!
4

One command is:

misstable summarize

But see also:

help missing##useful

and more generally:

help missing

2 Comments

I assume when it says "variables nonmissing or string", it means that I don't have missing values at all?
As I understand it, misstable will not count string missings, even with the all option.
1

Another option would be misschk from the SPost site. Type findit misschk to install it. Here's an example:

sysuse auto,clear
replace price=. if (_n==1|_n==3)  // additional missing values
misschk

Without specifying the varlist, misschk just checks all variables.

The standard output gives you the number as well as percentage of missing values on each variable.

Variables examined for missing values

   #  Variable        # Missing   % Missing
--------------------------------------------
   1  price                 2         2.7
   2  mpg                   0         0.0
   3  rep78                 5         6.8
   4  headroom              0         0.0
   5  trunk                 0         0.0
   6  weight                0         0.0
   7  length                0         0.0
   8  turn                  0         0.0
   9  displacement          0         0.0
   10 gear_ratio            0         0.0
   11 foreign               0         0.0

It also counts all the different missing patterns.

   Missing for |
         which |
    variables? |      Freq.     Percent        Cum.
---------------+-----------------------------------
 1_3__ _____ _ |          1        1.35        1.35
 1____ _____ _ |          1        1.35        2.70
 __3__ _____ _ |          4        5.41        8.11
 _____ _____ _ |         68       91.89      100.00
---------------+-----------------------------------
         Total |         74      100.00

Lastly, it summarizes the amount of missing values by cases.

Missing for |
   how many |
 variables? |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |         68       91.89       91.89
          1 |          5        6.76       98.65
          2 |          1        1.35      100.00
------------+-----------------------------------
      Total |         74      100.00

misschk also has a couple of other neat features with additional options you can find out about with help misschk.

Comments

1

missings from the Stata Journal offers a bundle of subcommands.

search dm0085 will yield a clickable link to the latest version of the file.

The write-up in the Stata Journal will emerge from behind a paywall on the publication of Stata Journal 18(4) in December 2018 or January 2019.

Before then, or even after, the examples in the Statalist announcement give much flavour.

Here is a token:

. webuse nlswork, clear 
(National Longitudinal Survey.  Young Women 14-26 years of age in 1968)

. missings report

Checking missings in all variables:
15082 observations with missing values

age           24
msp           16
nev_mar       16
grade          2
not_smsa       8
c_city         8
south          8
ind_code     341
occ_code     121
union       9296
wks_ue      5704
tenure       433
hours         67
wks_work     703

. missings report, min(1000)

Checking missings in all variables:
15082 observations with missing values

union     9296
wks_ue    5704

This command is considered to supersede nmissing.

ORIGINAL POST BELOW July 9 2014

Various commands help. See e.g. codebook. For one user-written command, install nmissing.

. search nmissing, historical

Search of official help files, FAQs, Examples, SJs, and STBs

FAQ     . . . . . .  Can I quickly see how many missing values a variable has?
    . . . . . . . . . . . . . . . . . .  UCLA Academic Technology Services
    7/08    http://www.ats.ucla.edu/stat/stata/faq/nmissing.htm

Example . . . . . . . . . . . . . . . . . . . . Useful non-UCLA Stata programs
    . . . . . . . . . . . . . . . . . .  UCLA Academic Technology Services
    7/08    http://www.ats.ucla.edu/stat/ado/world/

SJ-5-4  dm67_3  . . . . . . . . . .  Software update for nmissing and npresent
    (help nmissing if installed)  . . . . . . . . . . . . . . .  N. J. Cox
    Q4/05   SJ 5(4):607
    now produces saved results

SJ-3-4  sg67_2  . . . . . . . . . .  Software update for nmissing and npresent
    (help nmissing, npresent if installed)  . . . . . . . . . .  N. J. Cox
    Q4/03   SJ 3(4):449
    updated to include support for by, options for checking
    string values that contain spaces or periods, documentation
    of extended missing values .a to .z, and improved output

STB-60  dm67.1  . . . .  Enhancements to numbers of missing and present values
    (help nmissing if installed)  . . . . . . . . . . . . . . .  N. J. Cox
    3/01    pp.2--3; STB Reprints Vol 10, pp.7--9
    updated with option for reporting on observations

STB-49  dm67  . . . . . . . . . . . . .  Numbers of missing and present values
    (help nmissing if installed)  . . . . . . . . . . . . . . .  N. J. Cox
    5/99    pp.7--8; STB Reprints Vol 9, pp.26--27
    commands to list the numbers of missing values and nonmissing
    values in each variable in varlist

Here is an example:

. webuse nlswork
(National Longitudinal Survey.  Young Women 14-26 years of age in 1968)

. nmissing

age                                 24
msp                                 16
nev_mar                             16
grade                                2
not_smsa                             8
c_city                               8
south                                8
ind_code                           341
occ_code                           121
union                             9296
wks_ue                            5704
tenure                             433
hours                               67
wks_work                           703

2 Comments

I installed it and ran it but nothing at all showed up.
That could mean no missing values. Try sysuse auto followed by nmissing. You should see a report for rep78.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.