Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: table command returns different values every time

From   Richard Williams <>
To, "" <>
Subject   Re: st: table command returns different values every time
Date   Thu, 12 Dec 2013 00:44:34 -0500

I am with Nick -- I do not see any reason why you should be having problems. My theory is that there is something going on in the earlier code we aren't seeing. Are you, for example, generating a random variable, or drawing a random subsample? If so, you might need to set the seed first, e.g. start your code off with

set seed 123456

At 11:07 AM 12/11/2013, Nick Cox wrote:
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?

On 11 December 2013 14:36, Rijo John <> 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:
> *
> *
> *
*   For searches and help try:

Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  Richard.A.Williams.5@ND.Edu

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index