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

st: RE: RE: product function


From   Roger Newson <[email protected]>
To   [email protected]
Subject   st: RE: RE: product function
Date   Tue, 25 May 2004 18:44:13 +0100

At 18:00 25/05/04 +0100, Nick Cox wrote:
Woops. Sorry, Professor Feller!

. set obs 50
. gen i = _n
. gen double p = 1 - 1/365
. replace p = p[_n - 1] * (1 - _n / 365) in 2/l
. replace p = 1 - p
. scatter p i
Thanks for that trick, Nick. I wasn't aware that you could do recurrence relations in Stata that way. I always somehow assumed that the -replace- command in Stata created a whole new variable as a result, assigned its values on the basis of pre-existing variables, and then discarded the old variable and put the new one in its place. Evidently, it doesn't do that, and instead writes directly to the old variable, observation by observation, using the previous observation(s) as input if asked to do so. This trick will no doubt be useful next time I need to do a recurrence relation. I have noted, of course, that the last character in the 4th line is a l (the lower case version of L), and not a 1 (the digit one).

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

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