Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Understanding the mechanics of the sum() function
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: Understanding the mechanics of the sum() function
Date
Mon, 14 Nov 2011 10:46:00 +0000
`a' and `b' I take to be quite secondary here. There is a difference as -sum(`exp')- is affected by what is in the current observation if `exp' is so affected, and will return 0 in circumstances in which `exp' + what's inherited will return missing.
For example set
set obs 10
gen z = .
local a 0
local b 1
local exp z
generate y1 = `a' + `b' * sum(`exp')
gen y2 = .
replace y2 = `a' + `b' * (`exp' + cond(missing(y2[_n-1]), 0, y2[_n-1]))
l
I doubt you could make your code faster as your code requires more interpretation.
Nick
[email protected]
Billy Schwartz
Is there a difference between
. generate y = `a' + `b' * sum(`exp')
and
. generate y = .
. replace y = `a' + `b' * (`exp' + cond(missing(y[_n-1]), 0, y[_n-1]))
where `a', `b', and `exp' are arbitrary Stata expressions? If they're
not the same, is there a way of modifying the second to make it the
same as the first? (If they're the same in effect, is one faster than
the other?)
*
*
* 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/