Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Re: Decomposing integers


From   A Loumiotis <antonis.loumiotis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Decomposing integers
Date   Thu, 19 Jul 2012 16:14:07 +0300

Thanks as always Nick for you valuable help!

Antonis

On Thu, Jul 19, 2012 at 4:08 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> You said you wanted a local macro. Look at -inbase- for binary representations.
>
> Nick
>
> On Thu, Jul 19, 2012 at 1:48 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>>  clear
>>  set obs 100
>>  gen y = _n
>>  gen Y = mod(y, 32)
>>  egen bin = base(Y)
>>  gen wanted = reverse(bin) + string(floor(y/32))
>>
>> . l if y == 22 | y == 65
>>
>>      +--------------------------+
>>      |  y    Y     bin   wanted |
>>      |--------------------------|
>>  22. | 22   22   10110   011010 |
>>  65. | 65    1   00001   100002 |
>>      +--------------------------+
>>
>> The extra -egen- function here is -base()- from -egenmore- (SSC).
>>
>> Nick
>>
>> On Thu, Jul 19, 2012 at 1:00 PM, A Loumiotis
>> <antonis.loumiotis@gmail.com> wrote:
>>> The last local should contain 1 0 0 0 0 2.
>>>
>>> On Thu, Jul 19, 2012 at 2:54 PM, A Loumiotis
>>> <antonis.loumiotis@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have integer numbers of the following form:
>>>>
>>>> X=Sum[i=0/4](a[i]2^i)+(a[5]*2^5)
>>>>
>>>> where a[i] equals either 0 or 1 if i=0/4 and a[5] equals to any
>>>> positive integer or 0.
>>>>
>>>> Given this construction I would like to find the unique combinations
>>>> of a[i]'s that generated X.
>>>>
>>>> For example:
>>>>
>>>> X=22 was generated using a[1]=1, a[2]=1 and a[4]=1.
>>>> So I would like to construct a local that contains the following list
>>>> 0 1 1 0 1 0
>>>>
>>>> X=65 was generated using a[0]=1 and a[5]=2
>>>> So in this case the local should contain 1 0 0 0 0 1
>>>>
>>>> Is this possible?
> *
> *   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/
*
*   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/


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