Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: translation between binary system and the decimal system.


From   "Neil Shephard" <mdeasnds@fs1.ser.man.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: translation between binary system and the decimal system.
Date   Tue, 12 Oct 2004 15:18:59 +0100

> 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
neil.shephard@man.ac.uk
neil.shephard@mindless.com

"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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index