【问题标题】:How to check for ANY missing values如何检查任何缺失值
【发布时间】:2014-07-09 17:25:32
【问题描述】:

我知道一种查找和识别特定变量缺失值的方法。

对于变量avedmajor,我可以这样做

tab avedmajor, m

那么,

gen avedmajormissing=0

replace avedmajormissing=1 if avedmajor==.

但是如何在不检查每个变量的情况下查看我的数据集是否有任何变量中的缺失值?

谢谢。

【问题讨论】:

  • 你的第二个例子会更好gen avedmajormissing = missing(avedmajor)。另请注意,您的语法对扩展缺失值没有任何作用,仅适用于数字变量。
  • 我假设您的代码同时包含数字和字符串值?

标签: stata


【解决方案1】:

一个命令是:

misstable summarize

另见:

help missing##useful

更一般地说:

help missing

【讨论】:

  • 我假设当它说“变量非缺失或字符串”时,这意味着我根本没有缺失值?
  • 据我了解,misstable 不会计算字符串缺失,即使使用all 选项也是如此。
【解决方案2】:

我会在建议的解决方案中添加mdesc 命令。根据descriptionmdesc

生成一个包含缺失值数量、总数量的表格 案例,以及 varlist 中每个变量的缺失百分比。 mdesc 工作 具有数字和字符变量。

misstable 解决方案的优势在于它可以一次性处理数字和字符串变量。

sysuse auto
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
----------------+-----------------------------------------------

【讨论】:

  • 如果有兴趣,请通过 ssc inst mdesc 在 Stata 中安装,而不是通过您的浏览器。
【解决方案3】:

另一个选项是来自 SPost 站点的misschk。输入findit misschk 进行安装。这是一个例子:

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

不指定varlistmisschk 只检查所有变量。

标准输出为您提供每个变量缺失值的数量和百分比。

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

它还计算所有不同的缺失模式。

   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

最后,它按案例汇总了缺失值的数量。

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 还有一些其他简洁的功能,您可以通过help misschk 找到更多选项。

【讨论】:

    【解决方案4】:
    Stata Journal 中的

    missings 提供了一组子命令。

    search dm0085 将产生一个指向文件最新版本的可点击链接。

    the Stata Journal 中的文章将出现在 2018 年 12 月或 2019 年 1 月 Stata Journal 18(4) 出版的付费墙后面。

    在此之前,甚至之后,in the Statalist announcement 的示例给人以很大的味道。

    这是一个令牌:

    . 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
    

    此命令被视为取代nmissing

    2014 年 7 月 9 日以下的原始帖子

    各种命令帮助。参见例如codebook。对于一个用户编写的命令,安装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
    

    这是一个例子:

    . 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
    

    【讨论】:

    • 我安装并运行它,但什么也没有出现。
    • 这可能意味着没有缺失值。尝试sysuse auto,然后是nmissing。您应该会看到rep78 的报告。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    相关资源
    最近更新 更多