Announcement

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

  • List of variables with missing values

    Hello
    I am new to Stata and I'm currently studying the language. I have been able to do some stuff but I can't seem to do this in a optimized way.
    For simplification ,let's say I have:

    x1 x2 x3 x4
    8 5 3 1
    5 . 3 9
    6 1 3 6
    4 . . 8

    I want to list all variables that has a missing value:
    x1 x2 x3 x4
    5 . 3 9
    4 . . 8


    I could do
    Code:
    list x1 x2 x3 x4 if missing(x1) | missing(x2) | missing(x3) | missing(x4)
    but for large datasets this seems pretty annoying. How could I do it with a foreach command?
    Thanks in advance.

  • #2
    Several ways there are depending how your variables are named:
    1.
    Code:
    foreach var of varlist x1-x4 {
    li `var' if missing(`var')
    }
    2.

    Code:
    forval i=1/4  {
    li x`i'  if missing(x`i')
    }



    Roman

    Comment


    • #3
      It sounds as if you want to list all observations with missing values.

      See missings as one of various tools to tell you about missing data.

      http://www.stata-journal.com/article...article=dm0085 is the write-up.

      If that's not accessible to you or you don't want to pay USD 11.75 (none of which would go to me!), then the announcement at

      http://www.statalist.org/forums/foru...aging-missings

      is free and runs through the main possibilities.

      Download the files from the Stata Journal site, which you can do regardless of whether you have current access to the Journal itself.

      On the official side, http://www.stata.com/help.cgi?misstable is one place to start.

      Comment


      • #4
        Originally posted by Roman Mostazir View Post
        Several ways there are depending how your variables are named:
        1.
        Code:
        foreach var of varlist x1-x4 {
        li `var' if missing(`var')
        }
        2.

        Code:
        forval i=1/4 {
        li x`i' if missing(x`i')
        }


        that didn't work as expected. But because you put "list var". I just removed the var and got it show the infos as I expected.
        Thanks for you help!

        Comment


        • #5
          Originally posted by Nick Cox View Post
          It sounds as if you want to list all observations with missing values.

          See missings as one of various tools to tell you about missing data.

          http://www.stata-journal.com/article...article=dm0085 is the write-up.

          If that's not accessible to you or you don't want to pay USD 11.75 (none of which would go to me!), then the announcement at

          http://www.statalist.org/forums/foru...aging-missings

          is free and runs through the main possibilities.

          Download the files from the Stata Journal site, which you can do regardless of whether you have current access to the Journal itself.

          On the official side, http://www.stata.com/help.cgi?misstable is one place to start.
          hmm that didn't get to show my datas I expected, but that misstable function will surely help me in the futute. Thank you =)

          Comment


          • #6
            Hi George Scotton , I think tabmiss is really useful for summaries of missing data. It's not on ssc, but if you type
            Code:
            findit tabmiss
            into Stata, you'll see the link and can download it from there. Here's a quick tutorial on it: http://www.ats.ucla.edu/stat/stata/faq/cnt_charmiss.htm

            Comment


            • #7
              George Scotton:

              hmm that didn't get to show my datas I expected, but that misstable function will surely help me in the futute.
              Sorry, I can't decode that. For the record, this is a sample of what your dataset example would yield:

              Code:
               
              * code 
              clear 
              input x1    x2    x3    x4
              8    5    3    1
              5    .    3    9
              6    1    3    6
              4    .    .    8
              end 
              missings report
              missings list 
              
              * results 
              . missings report
              
              Checking missings in all variables:
              2 observations with missing values
              
              x2   2
              x3   1
              
              . missings list 
              
              Checking missings in all variables:
              2 observations with missing values
              
                   +---------+
                   | x2   x3 |
                   |---------|
                2. |  .    3 |
                4. |  .    . |
                   +---------+
              the first being similar in spirit to tabmiss (UCLA).


              Comment

              Working...
              X