Statalist


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

Re: st: sum() returns different results every time, why?


From   Johanna Jiménez <johannajimenezstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sum() returns different results every time, why?
Date   Sun, 2 Aug 2009 00:06:43 -0400

Hi everyone,

Thanks for your suggestion but maybe I didn't give enough information.
 Let me explain.

Each observation is a household with an unique identifier, income and
expenditures, plus a frequency weight.  Before to execute the code I
sent, I sort household by income and define deciles with "xtile"
command.  So, I think that the problem wouldn't be that exists another
identifier.

Besides, I was comparing three databases with results and I found that
the difference in each "acumparting_exp" is from third or fourth
decimal. In any case, the results would have to be the same, but they
don't.

Thanks for your help.

Kind regards,

Johanna







On Sat, Aug 1, 2009 at 8:30 PM, Tim<lists@timbp.com> wrote:
> My guess is decil and rincome do not uniquely identify the observations. In
> that case your sort order will not necessarily be the same, so you will be
> accumulating parting_exp in a different order each time.
>
> Tim Badgery-Parker
> lists@timbp.com
>
> Johanna Jiménez wrote:
>>
>> Hi everyone,
>>
>> I have a question for you....I have executed this code using the same
>> data, with 9940 observations, several times:
>>
>>
>>
>> sort decil rincome
>>
>> gen double rinc_exp= rincome * facexp
>>
>> egen double totrinc_exp = total (rinc_exp)
>>
>> gen double parting_exp= rinc_exp / totrinc_exp
>>
>>
>>
>> gen double acumparting_exp= sum(parting_exp)
>>
>>
>> The problem is the last command.  Each time I execute it,
>> “acumparting_exp” changes, this means that the running sum of
>> “parting_exp” varies for each observation each time I run my do-file.
>> I don´t know why sum() is different every time. I have tried to change
>> storage type of variables, drop some observations, but always occurs
>> the same. Could someone help me, please?
>>
>> Probably, my question is a little silly, but I don’t understand what
>> it’s happening and also, this has an effect on other commands and a
>> bootstrap program I wrote.   Besides, I executed these commands with
>> other variables as expenditures and I didn’t have the problem I
>> mentioned.  Just with incomes, commands return something different
>> every time.
>>
>> (Note: rincome and facexp are double (storage type of variables); and
>> database is always the same.)
>>
>> I appreciate your help.
>>
>> Kind regards,
>>
>>
>> Johanna J.
>>
>>
>
> *
> *   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   |   What's new   |   Site index