11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

328 [ U ] 23 Working with strings. encode sex, gen(gender). anova hbp genderNumber of obs = 1128 R-squared = 0.0123Root MSE = .214223 Adj R-squared = 0.0114Source Partial SS df MS F Prob > FModel .644485682 1 .644485682 14.04 0.0002gender .644485682 1 .644485682 14.04 0.0002Residual 51.6737767 1126 .045891454Total 52.3182624 1127 .046422593The magic here is to convert the string variable sex into a numeric variable called gender with anassociated value label, a trick accomplished by encode; see [U] 12.6.3 Value labels and [D] encode.23.3 Mistaken string variablesA variable might contain strings because of a mistake.Suppose that you have numeric data in a variable called x, but because of a mistake, x was madea string variable when you read the data. When you list the variable, it looks fine:. list xx1. 22. 2.53. 17(output omitted )Yet, when you attempt to obtain summary statistics on x,. summarize xVariable Obs Mean Std. Dev. Min Maxx 0If this happens to you, type describe to confirm that x is stored as a string:. describeContains dataobs: 10vars: 3size:160 (99.9% of memory free)storage display valuevariable name type format label variable labelx str4 %9sy float %9.0gz float %9.0gSorted by:x is stored as a str4.

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

Saved successfully!

Ooh no, something went wrong!