Jeph's solution doesn't work for me. I believe it is because the line:
bys ptid (visit): replace poststroke=(poststroke[_n-1]==1)
doesn't evaluate fully.
I assume Dilip would like to keep observations where the patient first
visits the hospital to be treated for stroke. Then here is a solution:
clear
input ptid visit stroke str15 admsn
1 1 0 1-Feb-05
1 2 0 1-Apr-05
1 3 0 19-Apr-05
1 4 0 14-Oct-05
1 5 0 30-Oct-05
1 6 1 18-Nov-05
1 7 0 2-Dec-05
2 1 0 10-May-05
2 2 0 30-Nov-05
3 1 0 8-Nov-05
4 1 1 4-Mar-05
4 2 0 9-Jul-05
4 3 0 15-Sep-05
5 1 0 31-Aug-05
6 1 0 20-Jul-05
6 2 0 3-Oct-05
7 1 1 27-Nov-05
8 1 1 29-Jul-05
8 2 1 18-Oct-05
9 1 0 13-Mar-05
9 2 0 11-Jul-05
9 3 0 6-Sep-05
9 4 0 28-Nov-05
9 5 0 19-Dec-05
10 1 0 29-Mar-05
10 2 0 4-Mar-05
10 3 0 25-Jul-05
11 1 1 10-Dec-05
12 1 1 16-Jan-05
12 2 0 19-Jan-05
12 3 0 22-Feb-05
end
gen date = date(admsn, "DM20Y")
format date %td
bys ptid: assert visit==_n
drop visit
bys ptid : g poststroke=(sum(stroke)!=0)
tab poststroke
keep if poststroke
T
On Mon, May 11, 2009 at 11:28 PM, Jeph Herrin <[email protected]> wrote:
> Try
>
> gen poststroke=stroke
> bys ptid (visit): replace poststroke=poststroke[_n-1]==1
> keep if poststroke
>
>
> Hope this helps
>
>
> Dr. Dilip K. Pandey wrote:
>>
>> Hi.
>> I am working with hierarchical data.
>> There are several hospital visit by patients. My outcome of interest is
>> stroke. Patient is diagnosed with stroke in one or other of hospital visit.
>> I would like to exclude visits prior to diagnosis of first stroke (index
>> hospitalization) but would keep informations on hospital visit after index
>> hospitalization. Example of dataset is below:
>>
>> Pt.ID visit stroke ADMSN_DT
>> 1 1 0 1-Feb-05
>> 1 2 0 1-Apr-05
>> 1 3 0 19-Apr-05
>> 1 4 0 14-Oct-05
>> 1 5 0 30-Oct-05
>> 1 6 1 18-Nov-05
>> 1 7 0 2-Dec-05
>> 2 1 0 10-May-05
>> 2 2 0 30-Nov-05
>> 3 1 0 8-Nov-05
>> 4 1 1 4-Mar-05
>> 4 2 0 9-Jul-05
>> 4 3 0 15-Sep-05
>> 5 1 0 31-Aug-05
>> 6 1 0 20-Jul-05
>> 6 2 0 3-Oct-05
>> 7 1 1 27-Nov-05
>> 8 1 1 29-Jul-05
>> 8 2 1 18-Oct-05
>> 9 1 0 13-Mar-05
>> 9 2 0 11-Jul-05
>> 9 3 0 6-Sep-05
>> 9 4 0 28-Nov-05
>> 9 5 0 19-Dec-05
>> 10 1 0 29-Mar-05
>> 10 2 0 4-Mar-05
>> 10 3 0 25-Jul-05
>> 11 1 1 10-Dec-05
>> 12 1 1 16-Jan-05
>> 12 2 0 19-Jan-05
>> 12 3 0 22-Feb-05
>>
>>
>> There are close to 800,000 hospitalizations to work with. Please suggest
>> macro or stata program to drop observation (hospital visits) prior to index
>> hospitalization but not after. Thanks
>> Dilip
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/