stata 检测缺失值的方法

//检测缺失值方法:
//用.表示缺失值,将缺失值定义为无穷大
//方法一:检测当前行有几个变量是缺失值,Stata执行描述性统计命令时,会自动忽略变量的缺失值;执行回归命令时,如果其中某个变量包含缺失值,Stata忽略这个变量所属观测值上所有变量取值
egen miss=rowmiss(_all)
//方法二:检测当前行以pidhaizi开头的变量有几个是缺失值
egen miss=rowmiss(pidhaizi*)
//方法三:分别统计每个变量分别有几个缺失值
//安装
ssc install nmissing
// checking nmissing consistency and verifying not already installed...
// installing into C:\Users\admin\ado\plus\...
// installation complete.
. nmissing
//
// age             51476
// pidhaizi        42208
// pidhaizia       42964
// pidhaizib       85696
// pidhaizic       88235
// pidhaizid       88662
// pidhaizie       88771
// pidhaizif       88808
// pidhaizig       88828

//方法四:

. codebook age
//
// ---------------------------------------------------------------------------
// age                                                                    年龄
// ---------------------------------------------------------------------------
//
//                   Type: Numeric (double)
//                  Label: age, but 93 nonmissing values are not labeled
//
//                  Range: [-8,102]                      Units: 1
//          Unique values: 94                        Missing .: 51,476/88,830
//
//               Examples: 44    
//                         76  
//方法五:  
ssc install mdesc
mdesc
//     Variable    |     Missing          Total     Percent Missing
// ----------------+-----------------------------------------------
//             pid |           0         88,830           0.00
//           fid18 |           0         88,830           0.00
//             age |      51,476         88,830          57.95
//        pidhaizi |      42,208         88,830          47.52
//       pidhaizia |      42,964         88,830          48.37
//       pidhaizib |      85,696         88,830          96.47
//       pidhaizic |      88,235         88,830          99.33
//       pidhaizid |      88,662         88,830          99.81
//       pidhaizie |      88,771         88,830          99.93
//       pidhaizif |      88,808         88,830          99.98
//       pidhaizig |      88,828         88,830         100.00
//            miss |           0         88,830           0.00
//           conta |           0         88,830           0.00
// ----------------+-----------------------------------------------

 

posted @ 2023-03-26 07:08  myrj  阅读(2157)  评论(0编辑  收藏  举报