|
|
|
||||
|
|
|||||
. order
rename
label data
label variable
label define
label values
replace
recode
note:
notes
save, replace
Let's begin by using a new data set, schdat.dta, it looks like this:
id a1 t1 gender a2 t2 tgender 1 95 88 0 94 95 1 2 63 86 1 61 94 1 3 87 80 0 81 84 1 4 79 70 0 79 87 0 5 68 78 1 63 69 0 6 64 87 1 82 96 0 7 86 75 0 69 76 0 8 81 94 1 93 92 1 9 89 79 0 90 78 1 10 78 68 1 80 80 1 |
. use schdat, clear
describe
The describe tells us the names of the variables but doesn't provide much more information. Here's the scoop on the data: a1 and a2 are scores on two assignments, t1 and t2 are the scores on the midterm and final respectively, gender is the gender of the student (1=female and 0=male). The variable tgender is the gender of the teacher and is also scored 1=female and 0=male. None of this is obvious from looking at the data, so let's get organized.
. order id gender tgender a1 a2 t1 t2
rename a1 assign1
rename a2 assign2
rename t1 midterm
rename t2 final
rename gender female
rename tgender tfemale
The order command changes the order of the varibles. The four rename commands change the names of some of the variables to more meaningful ones. This is a good start but we really need to add some labels to make things clear
. label data "Fall 1999 Stat 100 Scores"
label variable female "student gender"
label variable tfemale "teacher gender"
generate totavg = (assign1 + assign2 + midterm + final) / 4
label variable totavg "total score, divided by 4"
describe
The label data command places a label on the whole dataset. The label variable command makes labels that help explain individual variables. The generate command makes total the sum of the assignments and the midterm and final. Next we need to assign labels to female and tfemale and make a variable with the grade in the class.
Let's make labels showing that female and tfemale are coded 1=female and 0=male.
label define sex 1 "female" 0 "male"
label values female sex
label values tfemale sex
describe
tab1 female tfemale
tab1 female tfemale, nolabel
The label define command creates a definition for the values 0 and 1 called sex. The label values command connects the values defined for sex with the values in female and tfemale.
. generate grade = totavg
recode grade 0/60=0 60/70=1 70/80=2 80/90=3 90/100=4
label define abcdf 0 "F" 1 "D" 2 "C" 3 "B"
4 "A"
label values grade abcdf
list grade totavg
The generate and recode commands make a new variable grade going from 1 to 5. Using label define and label values the values of grade are labeled A - F.
. note: gender is self-report
note: the final was a take-home exam
notes
save schdat2
use schdat2, clear
The note: (note the colon, ":") command allows you to place notes into the dataset. The command notes displays the notes. The save, replace saves the dataset as schdat2.dta.
The Stata Class Notes are available on the World Wide Web by visiting ...
http://www.ats.ucla.edu/stat/stata/notes/
The dataset schdat.dta can be loaded directly into Stata, over the Internet, using the
following command:
use http://www.ats.ucla.edu/stat/stata/notes/schdat
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services