Announcement

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

  • Tabm missing option not working

    I am tabulation multiple variable that have the same values (1-5).I need to see the missing values in the table but is not working. I remember that I used tabm, missing in the past and it worked. Any ideas why this is happening?
    Last edited by Marvin Aliaga; 24 Jul 2015, 14:07.

  • #2
    When look at the results from help tabm it informs me that a help file is not found, so tabm is not a built-in command. When I look at the result for the search for tabm, I do not see a tabm command. So it's not possible for me to even know what command you tried to run. Or did Stata simply report this:
    Code:
    . tabm
    unrecognized command:  tabm
    r(199);
    which speaks for itself: there is no tabm command in the installation of Stata.

    Please review the Statalist FAQ linked to from the top of the page, especially sections 9-12 on how to best pose your question to help the reader address it. As the FAQ implores,
    Never say just that something “doesn't work” or “didn't work”, but explain precisely in what sense you didn't get what you wanted.
    as well as
    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
    Last edited by William Lisowski; 24 Jul 2015, 18:18.

    Comment


    • #3
      tabm is from the tab_chi package at SSC (N.J. Cox). Install it by:
      Code:
      ssc install tab_chi
      The help tells:
      Code:
      missing specifies that observations with missing values are to be included. The default is that any observation with any missing value on the variables specified is excluded.
      I also find that the missing option does not do what the help tells; on the contrary it makes a listwise exclusion of all variables if one of them is missing. Without the missing option, a missing in one variable does not affect the display of other variables. In neither case it includes the missing values in the table.

      I like the tabm command; it can be very useful. But there is a mismatch between the help and the actual behaviour. I would like missing values to be included in the tabulation, too.

      Comment


      • #4
        Svend and William are entirely correct in what they say. Marvin's report of this working in the past but not now can't be checked directly, but he too is right that there is a problem. tabm's support for missing values is broken. Thanks for reporting that.

        Here is some revised code.

        Code:
         
        *! 2.1.0 NJC 25 July 2015 
        * 2.0.0 NJC 1 November 2010 
        * 1.4.0 NJC 4 November 2005 
        * 1.3.1 NJC 11 December 2002
        * 1.3.0 NJC 10 December 2002
        * 1.2.0 NJC 5 February 1999
        * 1.0.0 NJC 22 December 1998
        program tabm, byable(recall) 
                version 8.2 
                syntax varlist(min=2) [if] [in] [fw aw iw] ///
            [, TRanspose Valuelabel(string) MISSing replace *]
        
            marksample touse, novarlist
        
            if "`replace'" != "" & _by() { 
                di as err "replace not allowed with by:" 
                exit 198 
            } 
        
            qui count if `touse' 
            if r(N) == 0 error 2000 
        
                if "`exp'" != "" {
                        tempvar wt
                        gen `wt' `exp'
                        local w "[`weight' = `wt']"
                }
        
                capture confirm string variable `: word 1 of `varlist'' 
                local strOK = _rc == 0
            local j = 1 
        
                foreach v of local varlist {
                        capture confirm string variable `v'
                        if (`strOK' & _rc == 0) | (!`strOK' & _rc) {
                                local OKlist `OKlist' `v' 
                                local slist `slist' `v' `wt' 
                                local lbl`j' : variable label `v'
                                if `"`lbl`j''"' == "" local lbl`j' "`v'" 
                    local ++j 
                        }
                        else local badlist `badlist' `v'  
        
                }
        
                if "`badlist'" != "" { 
                di _n "{res}`badlist' {txt}different type, so excluded" 
            }
        
            local nvars : word count `OKlist' 
            // normal tabulation, no need to stack 
                if `nvars' == 1 { 
                        tab `OKlist' `w', `missing' `options'
                        exit 0
                }
        
                if "`vallbl'" == "" {
                        local 1 : word 1 of `slist'
                        local vallbl : value label `1'
                }
            // insurance policy 
                if "`vallbl'" != "" { 
                        tempfile flabels
                        qui label save `vallbl' using `"`flabels'"' 
                }
        
                preserve
                tempvar data
                stack `slist' if `touse', into(`data' `wt') clear
                label var _stack "variable"
                label var `data' "values"
                forval i = 1 / `nvars' {
                        label def _stack `i' `"`lbl`i''"', add
                }
                label val _stack _stack
        
                if "`vallbl'" != "" {
                        if `strOK' di _n as txt "may not label strings" 
                else {
                                capture label list `vallbl'
                                if _rc run `flabels' 
                    label val `data' `vallbl'
                        }
                }
        
                if "`transpose'" == "" tab _stack `data' `w', `missing' `options' 
            else tab `data' _stack `w' , `missing' `options'
            if "`replace'" != "" { 
                clonevar _values = `data' 
                if "`w'" != "" { 
                    clonevar _weight = `wt' 
                    label var _weight "weights" 
                } 
                restore, not 
            } 
        end
        Here is a test:

        Code:
          
        clear
        set seed 2803 
        set obs 10
        
        forval j = 1/5 {
            gen y`j' = cond(runiform() < 0.8, 42, .)
        }
        
        list 
        tabm y*
        tabm y*, missing 
        
        
        . list 
        
             +------------------------+
             | y1   y2   y3   y4   y5 |
             |------------------------|
          1. |  .   42   42   42   42 |
          2. | 42   42    .    .   42 |
          3. | 42   42    .   42   42 |
          4. | 42   42   42   42   42 |
          5. | 42   42   42   42   42 |
             |------------------------|
          6. | 42   42   42    .   42 |
          7. | 42   42   42    .   42 |
          8. | 42   42   42   42    . |
          9. | 42   42   42   42   42 |
         10. | 42   42   42   42   42 |
             +------------------------+
        
        . tabm y*
        
                   |   values
          variable |        42 |     Total
        -----------+-----------+----------
                y1 |         9 |         9 
                y2 |        10 |        10 
                y3 |         8 |         8 
                y4 |         7 |         7 
                y5 |         9 |         9 
        -----------+-----------+----------
             Total |        43 |        43 
        
        
        . tabm y*, missing 
        
                   |        values
          variable |        42          . |     Total
        -----------+----------------------+----------
                y1 |         9          1 |        10 
                y2 |        10          0 |        10 
                y3 |         8          2 |        10 
                y4 |         7          3 |        10 
                y5 |         9          1 |        10 
        -----------+----------------------+----------
             Total |        43          7 |        50
        I'll get a revised copy posted on SSC, but both Kit Baum and I are travelling a lot over the next few weeks.

        Comment


        • #5
          Thank you guys.Nick please let me know when this is fixed. Thank you!

          Comment


          • #6
            Should be up now on SSC.

            Comment

            Working...
            X