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]

RE: st: Verify that all values of a variable are mapped after -label values-

From   Toby Robertson <>
To   "" <>
Subject   RE: st: Verify that all values of a variable are mapped after -label values-
Date   Thu, 20 Jun 2013 21:38:45 +0000

In the absence of an answer I've come up with this solution to identify numeric values in the data file that are not present in the lookup file from numeric values to strings that I want to use as labels:

use datafile
collapse (count)N=somevar, by(myvar)
merge myvar using lookupfile, nokeep keep() unique sort

Which then permits checks like:

tab _m
list myvar N if _merge==1
assert _merge==3

etc. etc.

In other words, do an empty left join of the lookups onto a table of the values in the data, and see which if any values are not in the lookups. 

Of the suggestions offered:

- 'tab myvar, missing' and then eyeballing the data is OK for one-off interactive work but is not what I need in this context

- 'decode myvar' defeats the whole purpose of not introducing long string variables into a very large dataset

- 'labelbook mylabel, problem' seems to detect labels that are not used in the data, but not values in the data that are not present in the labels (and doesn't report what the values are anyway)

> From:
> To:
> Subject: st: Verify that all values of a variable are mapped after -label values-
> Date: Thu, 20 Jun 2013 19:48:57 +0000
> What is the easiest way to check whether, having applied a value label to a variable...
> label values myvar mylabel
> ...every value of myvar in the dataset is mapped to mylabel?
> I am using Stata 10, creating value labels from lookup files from numeric code variables to string descriptor variables using -labmask- followed by -label save-, and then applying them to the values of the numeric variables in very large datasets.
> The obvious solution might be to merge the string variable itself from the lookup file into the target file (after which I could check the integrity of the merge, use -labmask-, and drop the string variable again) because I want to avoid that because of file size and read time considerations.
> Thanks in advance to anyone who knows the answer offhand!
> Toby
> *
> * For searches and help try:
> *
> *
> * 		 	   		  
*   For searches and help try:

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