Generating ordered ("cascading") dummy variables (STB-6: srd11) ------------------------------------------------ ^cascade^ varname [^if^ exp] [^in^ range], ^generate(^newvar^)^ Description ----------- ^cascade^ adds a set of new dummy variables to your data set that are "cascad- ing"; that is, rather than dummy variables that are coded 0/1 for each partic- ular value in the variable (as occurs using ^tab varname, gen(newvar)^--see ^help tabulate^), this creates variables coded 0/1 where a 1 is given if the case has the value for that variable or any LOWER value for that variable; see the example below. Options ------- ^generate()^ is not optional. The name for the new variable should have no more than 6 characters--see the example, below. Remarks ------- Only variables with a type of ^byte^ can be used. If the variable can be a byte you can easily make it one using either ^compress varname^ or the ^recast^ command. However, the values do not have to start with 1 and they do not have to be consecutive--see example 2 in the STB6: srd11. This ado-file is useful when your categorical variable is ordered. In this case, each dummy variable shows the amount of change between categories rather than the amount of change between the category of interest and the reference category. An example is presented below. For more, including a discussion of the meaning of these dummy's in Cox proportional hazards and in logistic regression, see S. D. Walter, A. R. Feinstein, and C. K. Wells (1987), "Coding Ordinal Independent Variables in Multiple Regression Analyses", ^American^ ^Journal of Epidemiology^, vol. 125, pp. 319-323. Remarks, continued ------------------ The ado-file automatically uses the lowest category (i.e., the category with the lowest value) as the reference category. If instead you would like to use the highest category as the reference category, form a new variable that is equal to (lowest+highest category minus the old variable). Thus, if you have variable coded 1-4 and you want to use 4 as the reference category, just ^generate^ newvar ^= 5 -^ oldvar (e.g., 5-4=1; 5-2=3, etc.) If your values run from, say 12-41 and you want 41 to be the reference cate- gory, enter: ^generate^ newvar ^= 53 -^ oldvar (e.g., 53-41=12, etc.) Note that this trick only works if the lowest category is non-negative. After forming the new variable, proceed as above. Examples -------- . ^use auto^ (1978 Automobile Data) . ^compress^ mpg was int now byte rep78 was int now byte trunk was int now byte turn was int now byte foreign was int now byte make was str18 now str17 Example 1: ---------- . ^cascade rep78 if rep78!=., gen(rep78)^ The following output can be obtained at any time by removing the asterisks (comment markers) from the second and third last lines of the ado file. This output shows the resulting coding (an easier to read example has been made up and is shown in the STB insert by editing the output). Example 1, continued -------------------- -> rep78= 1 rep78 rep782 rep783 rep784 rep785 2. 1 0 0 0 0 -> rep78= 2 rep78 rep782 rep783 rep784 rep785 10. 2 1 0 0 0 -> rep78= 3 rep78 rep782 rep783 rep784 rep785 40. 3 1 1 0 0 -> rep78= 4 rep78 rep782 rep783 rep784 rep785 58. 4 1 1 1 0 -> rep78= 5 rep78 rep782 rep783 rep784 rep785 69. 5 1 1 1 1 -> rep78= . rep78 rep782 rep783 rep784 rep785 74. . . . . . Author ------ Richard Goldstein, Qualitas, Brighton, MA. Email: goldst@@harvard.bitnet