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

Re: st: Keep value labels after -mvdecode-

From   Mike Lacy <>
Subject   Re: st: Keep value labels after -mvdecode-
Date   Wed, 28 Oct 2009 12:29:28 -0600

My question is not identical to the original subject but close enough to preserve the same subject and thread:

Elan Cohen: wrote:
>My data consists of different types of missing values currently stored as >negative integers. I'm using -mvdecode- to code them as missing, but I'd >like to tranfer the value labels along with it. Is this possible?

My situation is a more general case, I think. I have a listing of which values denote some kind of missing data situation for each of several hundred variables. I want to recode them to missing (.a, .b, ...) and retain the original value labels. I cannot rely on the same numerical codes being used to denote the same missing value situations for different variables. So, for example, I might have:

maritalstatus 0 9

ethnicity  0 99

where the value labels for maritalstatus are 0 = "refused", and 9 = "not applicable because of age"; and the variable labels for ethnicity are 0 = "question skipped for this respondent" and 99 = "respondent undecided".

The desired outcome would be that for maritalstatus, 0 is recoded to .a, and 9 to .b, with the marital status label modified so that .a has the label "refused" and .b has not applicable...". Ethnicity would be handled in parallel, but not identically, given the different meaning of 0.

The only solution I could come up with, which worked but seemed inconvenient, was to do the recode for each value, put the value label into a local, modify the label, reassign it, etc.

prog rectomiss  // handles the recode for one variable
args varname v1 v2 v3 v4 v5   //clumsy I know
local misslist = ".a .b .c .d .e" // five should be enough
tokenize `misslist'
local i = 1
foreach val of numlist `v1' `v2' `v3' `v4' `v5' {
   local misscode = ``i''
   recode `varname' (`val' = `misscode')
   local ++i
   local labelname: value label `varname'
   if "`labelname'" != "" { //blank
      local lblstrg: label(`varname') `val'
      label define `labelname' `misscode' "`lblstrg'", add
      label values `varname' `labelname'
// sample usage
// rectomiss ethnicity 0 99
// rectomiss maritalstatus 0 99

This seemed quite a bit of messing around for a simple task, a.though the execution for fast. Are there simpler ways to do this? I'd find that instructive.

(The application, by the way, might be of interest to some U.S. social scientists. The Stata version of the General Social Survey files are distributed with a do-file to recode all the missing values codes to ".", which loses the original value labels and distinctions for different reasons for missing values. If I had a decent simpler way to do what I did above, I'd pass it on to the folks that distribute the data.)

Mike Lacy
Fort Collins CO USA
(970) 491-6721 office

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index