Announcement

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

  • Listing variables with highest number of -99- observations

    Hi All,

    I was wondering if you could help me with writing up a small script.

    Right now I have a large dataset (over 2000 vars) and each var has values corresponding to categorical responses.

    One of my responses which is consistent throughout the entire dataset is the value "99" which corresponds to an "I don't know" response.

    I was wondering if there was some script I could write that would provide me with a list of variables with the most number of "99" responses, or a list of variables where the number of "99" responses is over 60% of the observations in that variable?

    I just want to know if there are any variables getting a disproportionate number of "I dont know" responses.

    Thank's for the help in advanced!

    -Ryan

  • #2
    Code:
    *sandbox 
    clear
    set obs 10
    quietly forval j = 0/10 { 
        gen x`j' = 99 if _n <= `j' 
    } 
    
    * install from Stata Journal 
    findname, type(numeric) any(@==99) local(varlist) 
    
    tempname foo 
    postfile `foo' str32 varname count using 99results, replace 
    
    quietly foreach v of local varlist { 
       count if `v' == 99 
       post `foo' ("`v'") (`r(N)') 
    }
    
    postclose `foo' 
    
    use 99results, clear 
    
    list 
    
        +-----------------+
         | varname   count |
         |-----------------|
      1. |      x1       1 |
      2. |      x2       2 |
      3. |      x3       3 |
      4. |      x4       4 |
      5. |      x5       5 |
         |-----------------|
      6. |      x6       6 |
      7. |      x7       7 |
      8. |      x8       8 |
      9. |      x9       9 |
     10. |     x10      10 |
         +-----------------+
    
    
    
    gsort -count 
    
    list 
    
         +-----------------+
         | varname   count |
         |-----------------|
      1. |     x10      10 |
      2. |      x9       9 |
      3. |      x8       8 |
      4. |      x7       7 |
      5. |      x6       6 |
         |-----------------|
      6. |      x5       5 |
      7. |      x4       4 |
      8. |      x3       3 |
      9. |      x2       2 |
     10. |      x1       1 |
         +-----------------+

    Comment

    Working...
    X