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/