> I would like to generate 4 dummies for a new category identification.
>
> Cat_id Cat4 Cat3 Cat2 Cat1
> 1 0 0 0 1
> 2 0 0 1 0
> 3 0 0 1 1
> 4 0 1 0 0
> ...
> 10 1 0 1 0
> 11 0 0 1 1
> ...
>
> i.e. it is a simple translation between binary system and the decimal
> system. Is there a command for this?
>
something like the following should work...
forval x = 1/4{
gen Cat`x' = cond(Cat_id == `x', 1,0)
}
Note that Stata is case-sensitive, and I've used the variable names exactly as you've
typed them.
For more info see Nick Cox's Stata Journal Column (in particular the one in volume 2(2)
titled "How to face lists with fortitude"), as well as -man functions-.
HTH's
Neil
Neil Shephard
Genetics Statistician
ARC Epidemiology Unit, University of Manchester
[email protected]
[email protected]
"If your result needs a statistician then you should design a better experiment" -
Ernest Rutherford
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/