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.

340 [ U ] 25 Working with categorical data and factor variablesfor variables that divide the data into more than two groups, and let’s use the term indicator variablefor categorical variables that divide the data into exactly two groups.Stata can convert continuous variables to categorical and indicator variables and categorical variablesto indicator variables.25.1.1 Converting continuous variables to indicator variablesStata treats logical expressions as taking on the values true or false, which it identifies with thenumbers 1 and 0; see [U] 13 Functions and expressions. For instance, if you have a continuousvariable measuring a person’s age and you wish to create an indicator variable denoting persons aged21 and over, you could type. generate age21p = age>=21The variable age21p takes on the value 1 for persons aged 21 and over and 0 for persons under 21.Because age21p can take on only 0 or 1, it would be more economical to store the variable as abyte. Thus it would be better to type. generate byte age21p = age>=21This solution has a problem. The value of age21 is set to 1 for all persons whose age is missingbecause Stata defines missing to be larger than all other numbers. In our data, we might have nosuch missing ages, but it still would be safer to type. generate byte age21p = age>=21 if age=21that may have occurred to you:. generate age21p = 1 if age>=21That does not produce the desired result. This statement makes age21p 1 (true) for all persons aged21 and above but makes age21p missing for everyone else.If you followed this second approach, you would have to combine it with. replace age21p = 0 if age

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

Saved successfully!

Ooh no, something went wrong!