Bookmark and Share

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]

st: table command returns different values every time


From   Rijo John <[email protected]>
To   stata <[email protected]>
Subject   st: table command returns different values every time
Date   Wed, 11 Dec 2013 20:06:01 +0530

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/


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