Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Carry forward an observation within a time frame


From   "Benigno Rodriguez, MD" <[email protected]>
To   [email protected]
Subject   st: Carry forward an observation within a time frame
Date   Tue, 8 Oct 2013 21:08:57 -0400

Dear Stata listers:

I have a panel dataset that consists of multiple visits on multiple subjects at some of which a CD4 value is obtained. My objective is to carry forward the CD4 value to visits for which it is missing, but only if a value is available within the 4 months prior.

I recognize the problem as one of spells, and have read Nick Cox's excellent article on spells from 2007, as well as his column on lists from 2002 (which I recognize as even more relevant to my problem), but despite his heroic efforts at a foolproof introduction to for and its variants, programming does not seem to get through my thick skull easily. Could I get a hand with this, ideally not involving code? Below is a relevant excerpt of the dataset, with the desired result in the last column.

Thank you very much in advance.

patid	date		CD4	desired
1007	5-May-55	.	.
1007	1-Jan-00	.	.
1007	3-Apr-02	5	5
1007	8-Apr-02	.	5
1007	11-Apr-02	.	5
1007	13-May-02	.	5
1007	14-May-02	4	4
1007	17-Jun-02	9	9
1007	12-Nov-02	.	.
1007	27-Jan-03	6	6
1007	17-Mar-03	.	6
1007	14-Apr-03	0	0

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index