Using Stata for Survey Data Analysis
Minot
Page 27
recode varname oldvalue
=newvalue oldvalue
=newvalue … [
if exp] [
in range]
Here are some examples:
recode x 1=2
changes all values of x=1 to x= 2
recode x 1=2 3=4
in the variable x, changes 1 to 2 and 3 to 4
recode x 1=2 2=1
in the variable x, exchanges the values 1 and 2
recode x 1=2 *=3
in the variable x, changes 1to 2 and all other values to 3
recode x 1/5=2
in the variable x, changes 1 through 5 to 2
recode x 1 3 4 5 = 6
in the variable x, changes 1, 3, 4 and 5 to 6
recode x .=9
in the variable x, changes missing to 9
recode x 9=.
in the variable x, changes 9 to missing
Notice that you can use some special symbols in the recode command:
*
means
all other values
.
means missing values
x/y
means
all values from x to y
x y
means values x and y
In Example 11, we create a new variable called maritalstat that indicates
whether a head of household
is 1) married or separated, 2) never married, or 3) divorced or widowed. It is
based on the variable
b21_q4 in the households.dta data file.
Example 11. Using “recode “to define a new variable
Do'stlaringiz bilan baham: