[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Eva Poen" <eva.poen@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: different result each time |

Date |
Thu, 25 Sep 2008 11:10:56 +0100 |

Rajesh, do you mean the "stable" option of -sort-? I'm not sure I understand how you can end up with this problem just because of a -merge-. For -merge- to work, your data have to be -sort-ed. But I think the problem is created when you feed your data to the loop that you are running. Unless you -keep in- or -drop in- after the merge and before the loop, the sort order of the data should not play any role at all. So, instead of using the "stable" option with -sort-, I'd make sure I uniquely identify with -sort- and then use the "if" qualifier instead of the "in" qualifier when selecting the sample to run the loop on. You want to make sure you know exactly which observations the tests are run on, and that the sample is the one that you think you are using. Eva 2008/9/25 Rajesh Tharyan <R.Tharyan@exeter.ac.uk>: > Hi Eva, > > Thanks .. that was exactly the problem! I was doing a merge way upstream > before the section where I run the t-tests, I was doing select all and > running the do file and that was causing the problem. I think with the > stable option that problem seems to have gone away. > > Thanks > > Rajesh > Tel: +44 (0)1392 262544 > Fax: +44 (0)1392 262475 > E-mail: r.tharyan@exeter.ac.uk > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eva Poen > Sent: 25 September 2008 10:12 > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: different result each time > > 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 <R.Tharyan@exeter.ac.uk>: >> 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/

**Follow-Ups**:**Re: st: different result each time***From:*Neil Shephard <nshephard@nhs.net>

**References**:**st: testing for endogeneity with cluster()***From:*"ritashree chakrabarti" <hirup01@gmail.com>

**st: RE: testing for endogeneity with cluster()***From:*"Schaffer, Mark E" <M.E.Schaffer@hw.ac.uk>

**Re: st: different result each time***From:*"Eva Poen" <eva.poen@gmail.com>

- Prev by Date:
**Re: st: different result each time** - Next by Date:
**st: Re: predict in ivreg28** - Previous by thread:
**RE: st: different result each time** - Next by thread:
**Re: st: different result each time** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |