-replace- goes through the observations one by one, so it changes x[1]
to 0, and then you are subtracting 0 from subsequent observations.
This will do what you want:
set obs 10
gen x = _n
local a = x[1]
replace x = x - `a'
Jamie Griffin
Department of Infectious Disease Epidemiology
Imperial College School of Medicine
Norfolk Place
London W2 1PG
Tel: 020 759 43217
Email:[email protected]
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Sergey
Chernenko
Sent: 10 March 2005 8:57 AM
To: [email protected]
Subject: st: replace and variable subscripts
Dear Stata Users:
Is the following behavior of -replace- documented anywhere?
. set obs 10
obs was 0, now 10
. gen x = _n
. replace x = x - x[1]
(1 real change made)
. fl
+------------+
| x |
|------------|
1. | 0 |
2. | 2 |
3. | 3 |
4. | 4 |
5. | 5 |
|------------|
6. | 6 |
7. | 7 |
8. | 8 |
9. | 9 |
10. | 10 |
+------------+
I would have expected -replace- to subtract 1 from each observation, not
just the first one.
Thanks.
Sergey
*
* 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/
*
* 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/