Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Value label gaps


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Value label gaps
Date   Mon, 16 Jul 2012 14:20:13 +0200

On Mon, Jul 16, 2012 at 1:42 PM, Jakob Petersen <[email protected]> wrote:
> I would like to find variables with value label gaps and would appreciate
> some ideas.
>
> -labelbook,problems- does detect variables with value label gaps, but
> includes variables with breaks in the consecutive order of values (e.g.
> 1/2/3/4/98/99), where the higher numbers could represent expected non-valid
> codes.
>
> -decode- could be used, but is very slow

Here is one idea, which makes heavy use of extended macro functions.
These are documented in -help extended_fcn-. (Though I always forget
and instead type -help macro- or -help local- and click on the link to
extended macro functions.)

*----------------------- begin example ---------------------
sysuse auto, clear
// introduce value gap error in foreign
la def origin 1 "",modify

ds, has(vallab)
local vars `r(varlist)'
foreach var of local vars {
    local problems ""
    local labname : value label `var'
    levelsof `var', local(levs)
    foreach i of local levs {
        if  `"`: label `labname' `i', strict'"' == "" {
            local problems  "`problems' `i'"
        }
    }
    local problems : list retokenize problems
    if "`problems'" != "" {
        local s    = cond(`: word count `problems'' > 1, ///
                          "s", "")
        local have = cond(`: word count `problems'' > 1, ///
                          "have", "has")
        di as txt "The following value`s' of variable " _c
        di as result "`var'" _c
        di as txt " `have' no value label:"
        di as result "`problems'"
    }
}
*------------------------ end example ----------------------

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index