Statalist The Stata Listserver


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

st: replace values of all members of a group with the values of one


From   "Hillgrove, Tessa (SA)" <[email protected]>
To   [email protected]
Subject   st: replace values of all members of a group with the values of one
Date   Tue, 23 May 2006 14:56:54 +1000

Title: replace values of all members of a group with the values of one

Hi all,
I am trying to work out what I imagine to be a simple problem, yet I can't quite put my finger on the solution.

I have appointment data for a group of donors, and I wish to replace the values of several fields with the values of particular appointment (as identified by def_inrange==1)

So what I would like to end up with is this:

+-----------------------------------------------+
     | donor_id          date        test   def_in~e |
     |-----------------------------------------------|
  1. |  0000001   27 Feb 2004   19aug2004          0 |
  2. |  0000001   15 Apr 2005   19aug2004          0 |
  3. |  0000001   22 Sep 2005   19aug2004          0 |
  4. |  0000001   19 Aug 2004   19aug2004          1 |
     |-----------------------------------------------|
  5. |  0000002   17 Feb 2004   10aug2004          0 |
  6. |  0000002   31 May 2004   10aug2004          0 |
  7. |  0000002   24 May 2005   10aug2004          0 |
  8. |  0000002   10 Aug 2004   10aug2004          1 |
     |-----------------------------------------------|
  9. |  0000003   21 Apr 2004   06sep2004          0 |
 10. |  0000003    6 Sep 2004   06sep2004          1 |

I have found the following from a FAQ, with no luck in my particular dataset, as Stata returns "(0 real changes made)"

. gen test = date if  def_inrange == 1
. bysort  donor_id  def_inrange date (test): replace test = test[1]

Can anyone tell me why this is not working?
If this is not appropriate, are there any quick and easy alternatives?

Previously I have used the following; running the 2nd line up to 13 times (to cover each appointment). I'm sure there's a more elegant approach!

.gen tempdate=date if def_inrange==1
.bysort progesaid (def_inrange): replace tempdate = tempdate[_n+1] if  tempdate >= .

Thanks in advance,
Tessa



E-mail Disclaimer:
Any personal information in this e-mail must be handled in accordance with the provisions of the Privacy Act 1988 [Cth].  The information contained in the e-mail may be confidential and if the person receiving the e-mail is not the intended recipient they should immediately advise ARCBS by e-mail response to the ARCBS sender and then deal with the e-mail as directed by ARCBS. The views expressed in the e-mail are those of the individual sender unless otherwise stated to be the views of ARCBS. No warranties are provided that the e-mail is computer virus or other defect free.




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