Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65573

-Twoway- : skipping missing observations

$
0
0
I am seeking to display the following simulated -twoway- graph, in which subjects are identified by the variable ID (which in this simulated data are 3, 8 and 9). I am wondering whether it is possible to display these data but skipping the missing ID rows, so that from the bottom up, the first row shows ID==3, the second ID==8, and so on. How would I modify the -twoway- command so that the rows for missing subjects not in the data (i.e. ID==1, 2, 4 and so on) are skipped? (Note: this graph combines multiple observations per subject, but I don't believe that's creating my problem of the space for missing ID's being kept in the graph.)

Code:
clear
input id    trtw    start    stop    stw    nn   event
3    0    0    12    1    2    1
3    0    17    548    0    2    0
8    0    0    53    1    15    1
8    0    54    108    1    15    0
8    0    109    201    1    15    0
8    0    202    203    1    15    0
8    0    206    216    1    15    0
8    0    218    317    1    15    0
8    0    319    324    1    15    0
8    0    325    344    1    15    0
8    0    347    354    1    15    0
8    0    356    376    1    15    0
8    0    379    458    1    15    0
8    0    460    464    1    15    0
8    0    476    487    1    15    0
8    0    491    545    1    15    0
8    0    546    554    1    15    0
9    1    0    284    1    2    1
9    1    286    602    0    2    0
end
bysort id: gen end = start[_n+1]
twoway     (rcap start stop id if id <=10, horiz)                    ///
        (rcap stop end id if id<=10 & event ==1 & id[_n+1]==id,    ///
            horiz lwidth(thick) lcol(black))                    ///
        (rcap stop stop id if id <10 & event == 1 & end==.,        ///
            horiz lwidth(thick) lcol(black)),                    ///
        leg(off) xtitle(Calendar time (days)) ytitle(Child)        ///
        xlabel(0(100)700) xscale(range(0 700))


Viewing all articles
Browse latest Browse all 65573

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>