Using Stata for Survey Data Analysis


Download 1.39 Mb.
Pdf ko'rish
bet27/61
Sana08.03.2023
Hajmi1.39 Mb.
#1252470
1   ...   23   24   25   26   27   28   29   30   ...   61
Bog'liq
2009 Usingstataforsurveydataanalysis (1)

 
 
 
Using Stata for Survey Analysis 
Page 22 
 

SECTION 6: CREATING NEW VARIABLES AND ADDING LABELS 
In the previous sections, we described how to explore the data using existing variables. In this 
section, we discuss how to create new variables and how to label them. When new variables are 
created, they are in memory and they will appear in the Data Browser, but they will not be saved on 
the hard-disk unless you use the save command. 
In this section, we will cover the following commands and topics: 
generate 
replace 
tab …, generate 
using operators 
using functions 
recode 
xtile
label variable 
label define 
label values 
#delimit 
 
generate
This command is used to create a new variable. It is similar to “compute” in SPSS. The syntax is: 
generate newvar = expression [if exp]
where “expression” is a mathematical statement like “price*quant” or “quant_kg/1000”. Several 
points about this command: : 
Unlike “compute” in SPSS, you cannot use “generate” to change the definition of an existing 
variable. If you want to change an existing variable, you need to use “replace,” 
You can use “gen” as an abbreviation for “generate” 
If the expression is an equality or inequality, such as (age>15), then the new variable will take 
the values 0 if the expression is false and 1 if it is true 
If you use “if”, the new variable will have missing values when the “if” statement is false 
For example, 
generate agehead2 = agehead*agehead create agehead squared variable 
.
gen yield = quant/area if area>0
create new yield variable if area is positive 
gen price = value/quant if quant>0 
create new price variable if quant is positive 
gen highprice = (price>1000) 
creates a dummy variable equal to 1 if the price is 
greater than 1000 and 0 otherwise  
 
 

Download 1.39 Mb.

Do'stlaringiz bilan baham:
1   ...   23   24   25   26   27   28   29   30   ...   61




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