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.

134 [ U ] 12 DataTechnical noteValue labels and variables may share the same name. For instance, rather than calling the valuelabel sexlabel in the example above, we could just as well have named it sex. We would then typelabel values sex sex to associate the value label named sex with the variable named sex.Example 8Stata’s encode and decode commands provide a convenient way to go from string variables tonumerically coded variables and back again. Let’s pretend that, in the example above, rather thancoding 0 for males and 1 for females, we created a string variable recording either "male" or"female".. use http://www.stata-press.com/data/r11/gxmpl5(2007 Employee data). describeContains data from http://www.stata-press.com/data/r11/gxmpl5obs: 7 2007 Employee datavars: 3 11 Feb 2009 15:37size:126 (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 ofbonusSorted by:. listempno sex salary1. 57213 male 34,0002. 47229 female 37,0003. 57323 male 34,0004. 57401 male 34,5005. 57802 female 37,0006. 57805 female 34,0007. 57824 male 32,500We now want to create a numerically encoded variable—we will call it gender—from the stringvariable. We want to do this, say, because we typed anova salary sex to perform a one-way ANOVAof salary on sex, and we were told that there were “no observations”. We then remembered that allStata’s statistical commands treat string variables as if they contain nothing but missing values. Thestatistical commands work only with numerically coded data.

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

Saved successfully!

Ooh no, something went wrong!