Rajesh,
I find this puzzling. The usual reason for differing results is that
some of the code requires random numbers, and the seed had not been
set (e.g. -set seed 123-). However, there is nothing random in your
code.
The only thing I can think of is that there is a random element
happening before the loop that you don't show us. Do you -sort- your
data, and then use -in-? E.g.
sort thisvar thatvar
keep in 1/200
foreach i in 1 2 3 4 7 0 {
...
}
If your -sort- statement does not uniquely identify observations, you
will get a different set of 200 observations each time you run the
loop. This example shows it for the auto data:
***
forvalues x = 1/5 {
sysuse auto, clear
gen id = _n
sort mpg
list id in 6/10
}
***
Hope this helps,
Eva
2008/9/25 Rajesh Tharyan <[email protected]>:
> Hi all,
>
> I am using the following code to do a bunch of t-tests and output the
> results to excel
>
> foreach i in 1 2 3 5 7 9 {
> ttest winar`i' if type=="C", by(class)
> scalar m1`i'=`r(mu_1)'
> scalar m2`i'=`r(mu_2)'
> scalar mdiff`i'=(`r(mu_1)'-`r(mu_2)')
> scalar t`i'=r(t)
> scalar p`i'=r(p)
> }
> matrix C =
> (m11,m12,m13,m15,m17,m19\m21,m22,m23,m25,m27,m29\mdiff1,mdiff2,mdiff3,mdiff5
> ,mdiff7,mdiff9\t1,t2,t3,t5,t7,t9\p1,p2,p3,p5,p7,p9)
> matrix rownames C= PB PS PB-PS t-stats p-val
> matrix colnames C= (per1) (per2) (per3) (per4) (per5) (per6)
> mat li C
> xml_tab C,append
> clear all
>
> Each time I run this I get different results. See below ( only the first row
> of matrix is shown)
>
> Run1
> PB 0.234 0.109 0.027 -0.020 0.006 0.186
>
> Run2.
> PB .22601096 .10431468 .02967896 -.00025647 .02184916 .21296798
>
> And so on. Why? Any thoughts
>
> Regards
> rajesh
*
* 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/