Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: replace and variable subscripts


From   "Griffin, Jamie T A" <james.t.griffin@imperial.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: replace and variable subscripts
Date   Thu, 10 Mar 2005 10:08:28 -0000

-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:james.t.griffin@imperial.ac.uk 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Sergey
Chernenko
Sent: 10 March 2005 8:57 AM
To: statalist@hsphsun2.harvard.edu
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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index