Statalist


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

st: RE: Re: Re: Data management


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Re: Data management
Date   Tue, 12 May 2009 21:20:19 +0100

Note that the approach behind Martin's suggestion is elaborated in
excruciating detail in an FAQ: 

FAQ     . . . . . . . . . . . . . . . First and last occurrences in
panel data
        3/07    How can I identify first and last occurrences
                systematically in panel data?
                <http://www.stata.com/support/faqs/data/firstoccur.html>

That FAQ is closely aligned with another: 

FAQ     . . . . . . . . . . . . . . . . . .  Dropping spells of missing
values
        3/07    How can I drop spells of missing values at the
                beginning and end of panel data?
                <http://www.stata.com/support/faqs/data/dropmiss.html>

Nick 
n.j.cox@durham.ac.uk 

Martin Weiss

You simply drop the ones where the (running) -sum- of the dummy is still

below 1


***
clear*

input PtID    visit    stroke   str12 ADMSNDT
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(ADMSNDT, "DM20Y")
format date %tdMonth_DD,_CCYY
compress

//before
list, noobs

//drop before stroke
bys PtID (visit): drop if sum(stroke)<1

//after
list , noobs
***

From: "Dr. Dilip K. Pandey" <dpandey@uic.edu>

> 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. 

*
*   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/



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