Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <n.j.cox@durham.ac.uk> |
To | "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Code to generate dummy variable from several categorical variables? |
Date | Mon, 16 Jan 2012 16:37:27 +0000 |
As -tab, gen()- is only available with a single variable, this suggestion seems to have no bearing on the question being asked. Nick n.j.cox@durham.ac.uk urbain thierry YOGO Try tabulate variable, gen(newvariable) summarize variable* where variable is the categorical variable and new variable, the new dummy. You may have as dummy variable as the number of modalities. 2012/1/16, daniel klein <klein.daniel.81@googlemail.com>: > Deborah, > > I am not really getting what you are trying to do here (and whether it > makes sense), since you are not giving any infromation on your > variables, but would replacing the line > > replace abnlX=2 if C==1 > > with > > replace abnlX=2 if C==1 & mi(abnlX) > > do what you want? > > > As a side issue, note that this > > replace abnlX=2 if C==1 & (B==. | B==0 | B==1) > > can be written as > > replace abnlX=2 if C==1 & inlist(B, ., 0, 1) > > See -help inlist()- and -help functions- > > Best > Daniel > > -- > Hello, > > I'm looking for code to generate a dummy variable from values of > several categorical variables which are not mutually exclusive. I've > tried to do this using the generate and replace commands but Stata is > changing the number of subjects in each dummy category as follows: * * 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/