Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Data management problem: unique combinations

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Data management problem: unique combinations
Date   Wed, 19 Jan 2005 23:05:36 -0000

-egen, group()- maps all combinations 
that occur in your data to integers 1 up. 

If you want all possible combinations 
to be coded systematically, you need 
some binary representation. Assuming
that -var1- to -var5- are coded 0 or 
1 this could be 

gen comb = 16 * var1 + 8 * var2 + 4 * var3 + 2 * var4 + var5 

or something producing a corresponding string. 
Often the latter is more transparent. There is a 
corresponding -egen- function -base()- in the 
package -egenmore- on SSC. 

[email protected] 

> I need help with a data management problem. What is an 
> efficient way of
> creating a categorical variable which consists of all unique
> combinations of a series of indicators variables?
> For example, I have a data set with five binary variables: var1, var2,
> var3, var4 and var5. A new variable is needed in which the categories
> represent all possible unique combinations of var1-var5.

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index