Statalist The Stata Listserver


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

st: the math function, sum( ), and missing


From   "Jitian Sheu" <jtsheu@mail.cgu.edu.tw>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: the math function, sum( ), and missing
Date   Fri, 24 Mar 2006 10:34:14 +0800

Dear listers:

Assume I have data as following:

Obs      x
1              1
2              .
3              .
4              1
5              .
6.             .
7              .
8              1
9              .
10            1

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:

Replace x=sum(x)

č 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):

Obs      x
1              1
2              1
3              1
4              2
5              2
6.             2
7              2
8              3
9              3
10            4

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[2]=old x[1]+old x[2]=1+0=1č we obtain the 2nd observation of x=1

When calculating x[3], the above new x[2] become a old one
Hence, by the same logic, new x[3]=old x[1]+old x[2]+old x[3]
Here, old x[1]=1, old x[3]=. (č missing=0 here)
However, old x[2] should be 1 instead of a missing value, right?
Therefore, I should have a new value of x[3]=1+1+)=2 instead of 1, right?
Can anyone tell me anything wrong here?

Thanks

JT



*
*   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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index