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

st: RE: Re: decimal to binary conversion


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: decimal to binary conversion
Date   Wed, 10 Mar 2004 13:56:12 -0000

-egenmore- on SSC has a function -base()- that 
gets you halfway with this. 

. egen binary = base(var1) 
. forval i = 1/6 {
.          gen str1 code`i' = substr(binary,`i',1) 
. } 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of 
> Jeffrey Simons
> Sent: 10 March 2004 13:48
> To: [email protected]
> Subject: st: Re: decimal to binary conversion
> 
> 
> I want to take a variable that is in decimal format and 
> convert it to a six
> digit binary number. Then take that and form six new 
> indicator variables.
> 
> For example,
> 
> . inbase 2 29
> 11101
> 
> Provides this. I would like to write a do file to loop 
> through the values of
> a variable and do this. Converting the answer to six new indicator
> variables.
> 
> So if var1 took on values of 15, 29, 35, ...
> I'd like to get
> 
> var1    v1a v1b v1c v1d v1e v1f
> 15      0   0   1   1   1   1
> 29      0   1   1   1   0   1
> 35      1   0   0   0   1   1
> ....

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index