Bookmark and Share

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

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

st: Value label gaps

From   Jakob Petersen <[email protected]>
To   [email protected]
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
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:

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