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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: how to recode when 9,99, 999 indicate real values and missing values for different variables


From   Amanda Fu <mandy.fu1@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: how to recode when 9,99, 999 indicate real values and missing values for different variables
Date   Sun, 16 May 2010 11:08:12 -0400

Hi all,

I have seen a couple of times that for some data sets the "not
answered" is coded as 9, 99, 999...... and the number of digit of 9
depends on the number of digit of the maximum  value of the variable.
It is convenient to analyze if recoding them into missing. But the
problem is, for some variables, 9 or 99 might be the real values. I
was wondering if there is any good way to deal with this kind of
recoding.
(In the past we have a discussion thread of using the value label
information such as "not answered"  to deal with this question. What I
am asking here is what if there are no such value labels ?)

For example, here are four variables :
var1 takes values: {1,2,3,4,9}
         where   9 means "not answered"
var2 takes values: {1,2,3,......8,9,10,11,12,99}
         where 99 means " "not answered"
var3 takes values: {1,2,3,...99,100,101,..,150,999}
         where 999 means " "not answered"
var4 takes values: {1,2,3,...999,1000,1001,..5000,9999}
         where 9999  means " "not answered"

Now I am thinking to recode int he following way:

foreach var of varlist *  {
sum `var'
replace `var'=. if r(max)<9       & `var'==9
replace `var'=. if r(max)<99     & r(max)>9       & `var'==99
replace `var'=. if r(max)<999   & r(max)>99    & `var'==999
replace `var'=. if r(max)<9999 & r(max)>999 & `var'==9999
}

I would like to hear if anyone has better method instead of this.
Thanks for your time!

Best wishes,
Amanda
*
*   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