Statalist


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

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


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: Replicating a sas loop in stata results in very slow computation time...
Date   Thu, 3 Apr 2008 08:31:50 -0400

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,  <[email protected]> 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,
>
>  [email protected]
>
>
>  *** 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/



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