[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: the math function, sum( ), and missing
Assume I have data as following:
I know that the math function, sum( ), provides the running sum of a given
variable, and I know that Stata treat missing as value of “0”
Therefore, if I type:
č for each observation of x, I am using the new sum(x) to replace it.
Therefore, the new data will be (after interactively execute it from Stata):
My question is following:
Because Stata is doing thing observation by observation(according to manual
), when I am typing –replace something-
č Stata “should” do it observation by observation,
Therefore, when using –replace x=sum(x)
č the first observation of x would be summation of all x’s observation from
1st obs up to the current observation, in this caseč1
The logic to obtain the second observation of x is the same,
č new x=old x+old x=1+0=1č we obtain the 2nd observation of x=1
When calculating x, the above new x become a old one
Hence, by the same logic, new x=old x+old x+old x
Here, old x=1, old x=. (č missing=0 here)
However, old x should be 1 instead of a missing value, right?
Therefore, I should have a new value of x=1+1+)=2 instead of 1, right?
Can anyone tell me anything wrong here?
* For searches and help try: