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

From |
PatrickT@umac.mo |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Replicating a sas loop in stata results in very slow computation time... |

Date |
Fri, 11 Apr 2008 02:03:06 +0800 |

Thanks very much Austin, I have looked into your suggestion: unfortunately it does not run appreciably faster. No, I have no idea about how many variables are being generated with -xi- in each iteration, but it is certainly far more than necessary! I must explain that the dataset is very large (in the millions) but runs in a matter of minutes with sas, so I expect that there must be a way to improve the computational speed. So I am still very much open to suggestions, if anyone out there has experience in coding loops involving -xi- with large datasets, I'd love to hear from you. I'm a stata novice. By the way there was an unnecessary semi-colon in the code you sent out Austin (and produces an error message), the code should read: xi i.age i.educ i.educ*age i.educ*age2 i.educ*age3 i.educ*age4 rather than xi: i.age i.educ i.educ*age i.educ*age2 i.educ*age3 i.educ*age4 I owe this very useful tip to a statalist exchange from 2004: http://www.datasets.org/statalist/archive/2004-10/msg00413.html, summed up here: ********************** When you use -xi- in combination with another command, for example, with -regress-, you must use the : (colon character). xi: regress y i.age But when you use -xi- alone with just the variable, then you must not use the colon character. xi i.age <-- notice that there is no colon in this usage of -xi- regress y _I* If you violate the rule, for example, xi: i.age then Stata will actually do the dummy variable creation, but it will also complain about the violation of syntax rules. With the colon character, Stata expects the immediately following text to be another command, such as -regress-. The complaint (error message) is that _Iage_ is not the name of any command that Stata can find. Joseph Coveney ********************** And yes, Austin, you are right that I intented to weigh the observations, but this got deleted in the code I sent out. Patrick. "Austin Nichols" <austinnichols@gmail.com> Do you realize you're generating many variables with -xi- in each iteration of the loop? Do you want something like the following? xi: i.age i.educ i.educ*age i.educ*age2 i.educ*age3 i.educ*age4 forv i=94/102 { logit yr00 _I* [pw=ihwt] if year~=`i' predict pyr00 if e(sample), p gen rw00=ihwt*pyr00/(1-pyr00) sum yr00 pyr00 rw00 if year~=100 drop pyr00 rw00 } Also the -sum- command is unweighted--is that what you intended? On Thu, Apr 3, 2008 at 3:24 AM, <PatrickT@umac.mo> wrote: > Hi there, > > I am trying to replicate a loop that runs well and fast in SAS, but is very > slow in STATA on my machine. > > Perhaps someone will spot some awkward piece of code in the following? > > many thanks for your attention, > > patrickt@umac.mo > > > *** STATA PROGRAM > set memory 700m ** couldn't do better than 700M > version 10 > use r2f3_glm.dta, clear > > local i 94 > while `i' ~= 103 { > xi: logit yr00 i.age i.educ i.educ*age i.educ*age2 i.educ*age3 i.educ*age4 > [pweight=ihwt] if year~=`i' > predict pyr00 if e(sample), p > gen rw00=ihwt*pyr00/(1-pyr00) > sum yr00 pyr00 rw00 if year~=100 > drop pyr00 rw00 > local i = `i'+ 1 > } > > exit > > > *** SAS PROGRAM > > proc logistic data=one(where=(year ne 100)) descending; > class yr00 educ agedum; > model yr00=agedum educ educ*age educ*age2 educ*age3 educ*age4; > weight ihwt; > output out=temp1 predicted=pyr00; > run; > > data temp1; > set temp1; > rw00=ihwt*pyr00/(1-pyr00); > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: RE: R: partially retrospective survival analysis** - Next by Date:
**st: Replicating a sas loop in stata results in very slow computation time....** - Previous by thread:
**Re: st: Replicating a sas loop in stata results in very slow computation time...** - Next by thread:
**Re: st: Replicating a sas loop in stata results in very slow computation time...** - Index(es):

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