Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: generating variable from combination of three categorical variable |

Date |
Wed, 18 May 2011 13:37:04 +0100 |

You have six rules, which I think can be collapsed to 4 in the first instance. (a) var1==0 & var2==0 & var3==0, (b) var4=1 if var1==1 & var2==1 & var3==1 (c) var4=2 if var1==2 & var2==2 & var3==2 (d) var4=1 if var1|var2|var3 is having 0 and 1 only (e) var4=2 if var1|var2|var3 is having 0 and 2 only (f) var4 is 3 if var1|var2|var3 is 0,1 and 2 gen var4 = 0 if max(var1, var2, var3) == 0 (a) replace var4 = 1 if max(var1, var2, var3) == 1 (b), (d) replace var4 = 2 if max(var1, var2, var3) == 2 (c), (e) replace var3 = 3 if (var1 + var1 + var2) == 3 (f) Now it is evident that you can simplify gen var4 = max(var1, var2, var3) replace var3 = 3 if (var1 + var1 + var2) == 3 Nick n.j.cox@durham.ac.uk prakash singh In my survey data, I have three categorical variable with 0, 1 and 2 as three category. Now I want to make a variable using combination of these three variables. The combination is such that generated variable var4 == 0 if var1==0 & var2==0 & var3==0, var4=1 if var1==1 & var2==1 & var3==1, var4=2 if var1==2 & var2==2 & var3==2, var4=1 if var1|var2|var3 is having 0 and 1 only var4=2 if var1|var2|var3 is having 0 and 2 only var4 is 3 if var1|var2|var3 is 0,1 and 2 for exmple (see below) var1 var2 var3 var4 0 0 0 0 1 1 1 1 2 2 2 2 0 1 2 3 0 1 1 1 1 2 0 3 I am using stata10. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: RE: generating variable from combination of three categorical variable***From:*Maria Fleischmann <maria.s.fleischmann@gmail.com>

**References**:**st: generating variable from combination of three categorical variable***From:*prakash singh <prakashbhu@gmail.com>

- Prev by Date:
**RE: st: New variable based on a sum of products of another variable** - Next by Date:
**Re: st: Using 64 bits stata to increase memory** - Previous by thread:
**st: generating variable from combination of three categorical variable** - Next by thread:
**Re: st: RE: generating variable from combination of three categorical variable** - Index(es):