Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: using information in value labels


From   "Alexander Nervedi" <alexnerdy@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: using information in value labels
Date   Wed, 14 Feb 2007 07:38:20 +0000

Thank you .... this is helpful and educative. I appreciate it a lot.


From: n j cox <n.j.cox@durham.ac.uk>
Reply-To: statalist@hsphsun2.harvard.edu
CC: statalist@hsphsun2.harvard.edu
Subject: Re: st: using information in value labels
Date: Tue, 13 Feb 2007 14:01:43 +0000

Those -recode- commands would be better if correct,
e.g.

recode `v' `l' = .

n j cox wrote:

I would not -recode- the original
variables. The scope for a large or even small mess
is such that it would be safer to do
this on copies of the original variables.
Or equivalently, keep your original
dataset file(s) very safe.

This is a sketch. Code not tested.

program fixmissing
version 8
syntax varlist
qui ds `varlist', has(vallabel)
local varlist "`r(varlist)'"

foreach v of local varlist {
qui levelsof `v', local(levels)
foreach l of local levels {
local label : label (`v') `l'
if index(`"`label'"', "Missing") {
recode `v' = .
}
else if index(`"`label'"', "missing") {
recode `v' = .
}
else if index(`"`label'", "did not respond") {
recode `v' = .a
}
// more lines likely
}
}
end

Alexander Nervedi

I have a complex survey dataset which has been helpfully cleaned - each
variable has its missing values coded with 9/99/999/999 or 98/998/9998 etc.
and things like Missing, Did not respond, refused to answer etc. are all
coded in as value labels.

I would like to treat all of these as missing and want to run a loop as
follow

local allvars x1 ... x100

foreach var of local allvars{

label list `var'
*pseudo code follows
scan label to see which levels include - "Missing", "missing", "did not
respond", etc
for each level `i' {
recode `var' (`i' = .)
}

}

I was wondering if this is something that could be reasonably be
implemented.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
_________________________________________________________________
Donít miss your chance to WIN 10 hours of private jet travel from Microsoft Office Live http://clk.atdmt.com/MRT/go/mcrssaub0540002499mrt/direct/01/

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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   |   What's new   |   Site index