Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sequence Index Plot

    Dear Stata Users

    I am trying to show how individuals move between a set of conditions or states over time. I think a sequence index plot should be able to visualize that.
    HTML Code:
    https://www.stata-journal.com/sjpdf.html?articlenum=gr0022
    My data is the summary of different horse behaviour over time. There are 6 different behaviour classes, and 19 individuals. Every row accounts for a second, and each second there is a classified behaviour (between 1 and 6).

    Code:
    . separate begin, by(type) . separate end, by(type)
    Code:
    graph twoway > (rbar begin1 end1 id, horizontal) > (rbar begin2 end2 id, horizontal) > (rbar begin3 end3 id, horizontal) > (rbar begin4 end4 id, horizontal) > (rbar begin5 end5 id, horizontal) > , legend(order(1 "education" 2 "apprenticeship" > 3 "employment" 4 "unemployment" 5 "inactivity") > cols(1) pos(2) symxsize(5)) > xtitle("months") yla(, angle(h)) yscale(reverse)
    This code has been used previously.

    My data set
    HorseID Time PredictedLF
    1 15:06:57 1
    1 15:06:58 1
    1 15:06:59 5
    1 15:07:00 5
    1 15:07:01 2
    1 15:07:02 4
    1 15:07:03 4
    2 09:38:10 4
    2 09:38:11 2
    2 09:38:12 3
    2 09:38:13 3
    2 09:38:14 4
    2 09:38:15 4
    2 09:38:16 4
    2 09:38:17 2
    2 09:38:18 4
    2 09:38:19 6
    2 09:38:20 6
    2 09:38:21 6
    Code:
    separate  Time, by ( PredictedLF)
    Which gave me 6 variables Time1 Time2 Time3 Time4 Time5 Time6
    I then used this to get start and end times for each classified behaviour.

    For example:
    Code:
    gen LFendLyingLF=1 if Time1~=. &(Time1 [_n+1] ==.)
    However when I used the code from above it did not work.

    Code:
    graph twoway (rbar  LFStartLyingLF LFendLyingLF HorseID, horizontal)(rbar  LFStartStep LFendStep HorseID, horizontal)(rbar  LFStartPaw LFendPaw HorseID, horizontal)(rbar  LFStartStand LFendStand HorseID, horizontal)(rbar  LFStartWS LFendWS HorseID, horizontal)(rbar  LFStartLyingR LFendLyingR HorseID, horizontal),legend (order(1 "Lying Left" 2 "Step" 3 "Pawing ground" 4 "Standing" 5 "Weight shift" 6 "Lying Right") cols(1) pos(2) symxsize(6))
    Any advice would be much appreciated. Thankyou for your time.

    Katrina
Working...
X