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   Jakob Petersen <[email protected]>
To   [email protected]
Subject   Re: st: Value label gaps
Date   Mon, 16 Jul 2012 13:59:10 +0100

On 16/07/2012 13:20, Maarten Buis wrote:
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

Thanks a lot - much faster.  Jakob
*
*   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