平军 发表于 2013-5-2 23:28 
help mvencode
help mvencode, help mvdecode dialogs: mvencode mvdecode
-------------------------------------------------------------------------------
Title
[D] mvencode -- Change missing values to numeric values and vice versa
Syntax
Change missing values to numeric values
mvencode varlist [if] [in], mv(#|mvc=# [\ mvc=#...] [\ else=#])
[override]
Change numeric values to missing values
mvdecode varlist [if] [in], mv(numlist | numlist=mvc
[\ numlist=mvc...])
where mvc is one of .|.a|.b|...|.z
Menu
mvencode
Data > Create or change data > Other variable-transformation commands
> Change missing values to numeric
mvdecode
Data > Create or change data > Other variable-transformation commands
> Change numeric values to missing
Description
mvencode changes missing values in the specified varlist to numeric
values.
mvdecode changes occurrences of a numlist in the specified varlist to a
missing-value code.
Missing-value codes may be sysmiss (.) and the extended missing-value
codes .a, .b, ..., .z.
String variables in varlist are ignored.
Options
+------+
----+ Main +-------------------------------------------------------------
mv(#|mvc=# [\ mvc=#...] [\ else=#]) is required and specifies the numeric
values to which the missing values are to be changed.
mv(#) specifies that all types of missing values be changed to #.
mv(mvc=#) specifies that occurrences of missing-value code mvc be
changed to #. Multiple transformation rules may be specified,
separated by a backward slash (\). The list may be terminated by the
special rule else=#, specifying that all types of missing values not
yet transformed be set to #.
Examples: mv(9), mv(.=99\.a=98\.b=97), mv(.=99\else=98)
mv(numlist | numlist=mvc [\ numlist=mvc...]) is required and specifies
the numeric values that are to be changed to missing values.
mv(numlist=mvc) specifies that the values in numlist be changed into
missing-value code mvc. Multiple transformation rules may be
specified, separated by a backward slash (\). See [[U]] 11.1.8
numlist for the syntax of a numlist.
Examples: mv(9), mv(99=.\98=.a\97=.b), mv(99=.\100/999=.a)
override specifies the protection provided by mvencode be overridden.
Without this option, mvencode refuses to make the requested change if
any of the numeric values are already used in the data.
Examples
---------------------------------------------------------------------------
Setup
. sysuse auto
Translate missing values in the data to 999
. mvencode _all, mv(999)
Change 999 values back to missing values
. mvdecode _all, mv(999)
List the data
. list rep78 if rep78 == .
Set rep78 to 999 in observation 3
. replace rep78 = 999 in 3
Try to translate missing values in the data to 999
. mvencode _all, mv(999)
Force the translation of missing values in the data to 999
. mvencode _all, mv(999) override
---------------------------------------------------------------------------
Setup
. sysuse auto, clear
List the data
. list rep78 foreign if rep78 == .
Translate missing values for rep78 to 998 if foreign is Domestic and
translate to 999 if foreign is Foreign
. mvencode rep78 if foreign == 0, mv(998)
. mvencode rep78 if foreign == 1, mv(999)
List the data
. list rep78 foreign if rep78 > 900
For rep78, translate 998 to . and 999 to .a
. mvdecode rep78, mv(998=. \ 999=.a)
List the data
. list rep78 foreign if rep78 >= .
---------------------------------------------------------------------------
Also see
Manual: [D] mvencode
Help: [D] generate, [D] recode