Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: table command returns different values every time
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: table command returns different values every time
Date
Wed, 11 Dec 2013 16:07:10 +0000
There are at least two problems in understanding this.
First, and obviously, we don't have your data to check this (and you
don't provide an alternative reproducible example).
Second, and more of a challenge, you are calling up -table- to show
some means in cells of a cross-classification. I may be missing
something, but there should be no way that depends on the sort order
of your data. Also, as you imply, that should be reproducible any way.
Any chance of seeing an example we can reproduce?
Nick
[email protected]
On 11 December 2013 14:36, Rijo John <[email protected]> wrote:
> Dear Statalist,
>
> I am running the following code to generate a certain table. Every
> time restart stata and run the code it returns results wherein some of
> the values are slightly different compared to the previous run. I am
> talking about differences at 2nd, 3rd or higher decimals. What can I
> do to make this stable? I think the difference is happening may be
> because the sorting order is changing every time I restart stata. It
> doesn't change within the same session. If I don't give the sort
> command in between it still changes every time I run the program.
>
> <---Code Begins --->
> local fruit "Apple Apricot Bananas Mango Orange"
> local num "1 2 3 4 5"
> local n : word count `fruit'
> forvalues i=1/`n'{
> sort id, stable
> local a : word `i' of `fruit'
> local b : word `i' of `num'
> gen `a'=0
> replace `a'=var1 if fruit==`b'
> table State sex if ag==2 [pw=mult], c(mean `a')
> }
> <---Code Ends --->
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/