[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Efficiency: was RE: Taking averages, etc.
> While it is possible to replace one value in a variable
> (say the 4th)
> replace x = y if _n == 4
> that code tests _n for every element. It's very wasteful,
> though you may
> not notice in most interactive sessions. In a program however, the
> replace x = y in 4
> will be about _N times faster. As this will typically be
> inside a loop
> dealing will each element of the variable, it may reduce
> execution time
> from O(_N squared) to O(_N).
This is an old song, but it deserves a replay.
There is one side-issue. Allan says
"this will typically be inside a loop
dealing will each element of the variable".
In Stata, that's not typical at all. Looping
explicitly over observations is sometimes
needed, but in the majority of cases it
is a sign that you've not seen the Stata way
to do something.
* For searches and help try: