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.

102 [ U ] 11 Language syntaxTyping infile str10(state region) v1-v5 using mydata would achieve almost the sameresult, except that the state and region values recorded in the data would both be assigned to str10variables. (We could then use the compress command to shorten the strings. See [D] compress; itis well worth reading.)Technical noteYou may append a colon and a value label name to numeric variables. (See [U] 12.6 Dataset,variable, and value labels for a description of value labels.) For instance, var1 var2:myfmt specifiesthat the variable var2 be associated with the value label stored under the name myfmt. This has thesame effect as typing the list var1 var2 and then subsequently giving the command label valuesvar2 myfmt.The advantage of specifying the value label association with the colon notation is that value labelscan then be assigned by the current command; see [D] input and [D] infile (free format).Example 17Typing infile int(state:stfmt region:regfmt) v1-v5 using mydata, automatic readsthe state and region data from the file mydata.raw and stores them as ints, along with the variablesv1 through v5, which are stored as the default storage type.In our previous example, both state and region were strings, so how can strings be stored in anumeric variable? See [U] 12.6 Dataset, variable, and value labels for the complete answer. Thecolon notation specifies the name of the value label, and the automatic option tells Stata to assignunique numeric codes to all character strings. The numeric code for state, which Stata will make upon the fly, will be stored in the state variable. The mapping from numeric codes to words will bestored in the value label named stfmt. Similarly, regions will be assigned numeric codes, which arestored in region, and the mapping will be stored in regfmt.If we were to list the data, the state and region variables would look like strings. state,for instance, would appear to contain things like AL, CA, and WA, but actually it would contain onlynumbers like 1, 2, 3, and 4.11.4.3 Factor variablesFactor variables are extensions of varlists of existing variables. When a command allows factorvariables, in addition to typing variable names from your data, you can type factor variables, whichmight look likei.varnamei.varname#i.varnamei.varname#i.varname#i.varnamei.varname##i.varnamei.varname##i.varname##i.varnameFactor variables create indicator variables from categorical variables and are allowed with mostestimation and postestimation commands, along with a few other commands.

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

Saved successfully!

Ooh no, something went wrong!