Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Generating dummy variables based on two categories..


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: Generating dummy variables based on two categories..
Date   Wed, 30 Jan 2013 15:21:12 -0500

make the two into one variable using -egen- with the "group" function:

egen newvar=group(oldvar1 oldvar2)

you can then use either -tabulate- with the gen option or you can use
factor variable notation (see -h fvvarlist-)

Rich

On 1/30/13 3:16 PM, Mukund Chari wrote:
> Dear Stata-listers,
> 
> I am trying to generate dummy variables based on two variables with multiple categories in each.
> The dummies need to represent each unique combination of the two variables.
> 
> UserID   Techlab               UserTechD1       UserTechD12     UserTechD13     UserTechD14     UserTechD15     UserTechD6                UserTechD7       UserTechD8       
>                                                 (Comb: 11)          (Comb: 21)          (Comb: 22)          (Comb: 23)          (Comb: 31)          (Comb: 32)                (Comb: 43)          (Comb: 51)          
> 1              1                              1                              0                              0                              0                              0                              0                              0                              0              
> 2              1                              0                              1                              0                              0                              0                              0                              0                              0
> 2              2                              0                              0                              1                              0                              0                              0                              0                              0
> 2              3                              0                              0                              0                              1                              0                              0                              0                              0
> 3              1                              0                              0                              0                              0                              1                              0                              0                              0
> 3              2                              0                              0                              0                              0                              0                              1                              0                              0
> 4              3                              0                              0                              0                              0                              0                              0                              1                              0
> 4              3                              0                              0                              0                              0                              0                              0                              1                              0
> 5              1                              0                              0                              0                              0                              0                              0                              0                              1
> 
> The tabulate: generate command uses only a single variable to create the dummies; not sure what to do when there are multiple variables.
> 
> Any help is most appreciated.
> 
> Best,
> Mukund.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index