Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: RE: loop [ignore previous one (from this message), sorry!!!]


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: RE: loop [ignore previous one (from this message), sorry!!!]
Date   Tue, 18 Feb 2003 09:09:26 -0000

Jun Xu
> 
> Thank you so much.  After I made that change "gen long 
> `pat02'=." it worked. 
>   Also thank you for your hints/program.  Probably I 
> shouldn't ve posted 
> this question.  Rather I better to take a course in 
> programming.  But if you 
> have the answer at hand, would you be able to give me some 
> general rules/if 
> possible, some tricks for this problem to be more 
> efficient?  This program 
> now works pretty fine with less than like 12 variables.  
> Everything works 
> fine except a bit slow (10 and less variables kind of fast 
> enough).  But 
> when I play around with it using like 15 variables, it just 
> takes forever to 
> produce the results (like 10 minutes).  I think it's 
> probably related to the 
> forval command in the middle part of this program.  But I 
> couldn't find a 
> better way.  Or, if I want program an ado file to do what I 
> want (exhaust 
> combinations), slowness should be expected. 

There are two root problems: 

1. The size of the problem grows with the number of 
variables k roughly as 2^k. E.g. 2^15 is 32768, 2^10 is 1024. 
This remains true whatever you do. 

2. Stata as an interpreted language is fast, but 
cannot be fast as compiled code. -forval- is pretty 
fast as interpreted code goes. Translating a -while- 
into a -foreach- or -forval- will speed your code up 
a bit, but possibly only by a small fraction. 

Nick 
[email protected] 

*
*   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