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: reverse tab y, gen(d)
From
Richard Williams <[email protected]>
To
[email protected], Statalist <[email protected]>
Subject
Re: st: reverse tab y, gen(d)
Date
Thu, 26 Sep 2013 18:18:00 -0500
At 04:49 PM 9/26/2013, Dimitriy V. Masterov wrote:
Is there a command that does the reverse of -tab y, gen(d)-? Say I
have 10 dummy variables d1-d10, and I want to make a single
categorical variable d that has values 1-10?
Something like this maybe? The egen command is the critical part.
sysuse auto, clear
tab1 rep78, gen(rep)
egen x = group(rep5 rep4 rep3 rep2 rep1)
tab2 rep78 x
Make sure values get assigned the way you want. I believe you have to
list the dummies in the reverse order of how you want the values assigned.
I suppose you could also do something like
gen x = d1 + 2*d2 + 3*d3... + 10*d10
I am assuming here that you mean a situation where a case has a value
of 1 on exactly one of the dummies and values of 0 on all others.
DVM
*
* 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/
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME: (574)289-5227
EMAIL: [email protected]
WWW: http://www.nd.edu/~rwilliam
*
* 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/