Using Stata for Survey Data Analysis


Download 1.39 Mb.
Pdf ko'rish
bet32/61
Sana08.03.2023
Hajmi1.39 Mb.
#1252470
1   ...   28   29   30   31   32   33   34   35   ...   61
Bog'liq
2009 Usingstataforsurveydataanalysis (1)

 
recode  
This command redefines the values of a categorical variable according to the rules specified. It is like 
the “recode” command in SPSS except that in Stata you do not use parentheses. The syntax is: 


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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Download 1.39 Mb.

Do'stlaringiz bilan baham:
1   ...   28   29   30   31   32   33   34   35   ...   61




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling