11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[ U ] 12.6 Dataset, variable, and value labels 135. encode sex, generate(gender). describeContains data from http://www.stata-press.com/data/r11/gxmpl5.dtaobs: 7 2007 Employee datavars: 4 11 Feb 2009 15:37size:154 (99.8% of memory free)storage display valuevariable name type format label variable labelempno float %9.0g Employee numbersex str6 %9s Sexsalary float %8.0fc Annual salary, exclusive ofbonusgender long %8.0g gender SexSorted by:Note:dataset has changed since last savedencode adds a new long variable called gender to the data and defines a new value label calledgender. The value label gender maps 1 to the string male and 2 to female, so if we were to listthe data, we could not tell the difference between the gender and sex variables. However, they aredifferent. Stata’s statistical commands know how to deal with gender but do not understand the sexvariable. See [D] encode.Technical notePerhaps rather than employee data, our data are on persons undergoing sex-change operations.There would therefore be two sex variables in our data, sex before the operation and sex after theoperation. Assume that the variables are named presex and postsex. We can associate the samevalue label to each variable by typing. label define sexlabel 0 "Male" 1 "Female". label values presex sexlabel. label values postsex sexlabelTechnical noteStata’s input commands (input and infile) can switch from the words in a value label back tothe numeric codes. Remember that encode and decode can translate a string to a numeric mappingand vice versa, so we can map strings to numeric codes either at the time of input or later.For example,. label define sexlabel 0 "Male" 1 "Female". input empno sex:sexlabel salary, labelempno sex salary1. 57213 Male 340002. 47229 Female 370003. 57323 0 340004. 57401 Male 345005. 57802 Female 370006. 57805 Female 340007. 57824 Male 325008. end

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!