Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Value label gaps


From   Jakob Petersen <jpeterb@essex.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: Value label gaps
Date   Mon, 16 Jul 2012 12:42:20 +0100

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

sysuse auto,clear
la def origin 1 "",modify  // introduce value gap error in foreign
findname,vallab
foreach v of varlist `r(varlist)' {
tempvar vs
decode `v',gen(`vs')
distinct `v'
local nv=`r(ndistinct)'
distinct `vs'
local nvs=`r(ndistinct)'
if `nv'!=`nvs' {
if `nv'<100 {
fre `v'
}
else {
di "`v' has value label gaps and >=100 distinct values"
}
}
}

Many thanks in advance,
Jakob Petersen

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index