Dear Statalist,

I have a dataset in long format:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float id double FEV1 float PartDat
 1  112.06 13458
 1 104.674 14906
 1   107.5 17592
 2  110.86 13670
 2  99.685 14951
 2    99.2 17592
 3   112.8 17592
 3  94.638 13618
 3 101.036 14656
 4    91.3 17592
 4  91.176 14651
 4  89.279 13115
 5   111.1 17592
 5 105.953 13226
 5 106.628 14903
 6    89.7 17592
 6  99.208 13121
 6  88.196 14899
 7  87.237 14948
 7  89.837 13641
 7    89.7 17592
 8  89.843 14992
 8  98.094 13178
 8    96.5 17592
 9 101.531 14906
 9   103.5 17592
 9  93.181 13461
10   84.45 14697
10    81.1 17592
10  81.826 13303
11   109.2 17592
11 115.967 13060
11 115.349 15001
12    96.6 17592
12   91.04 14950
12  78.532 13494
13   111.7 17592
13 105.391 14950
13 118.635 13523
14  78.887 13628
14    84.7 17592
14  85.425 14745
15  100.59 14950
15   104.9 17592
15 109.945 13639
16  91.703 14896
16    96.3 17592
16  93.205 13167
17  99.513 13654
17 102.001 14656
17    99.2 17592
18 113.858 14915
18   107.7 17592
18 113.249 13486
19  92.536 14915
19    93.5 17592
19  79.938 13487
20   100.3 17592
20 109.363 14992
20  93.709 13633
21    90.1 17592
21  83.376 13459
21  87.609 14906
22  89.126 13661
22  92.161 14651
22    81.8 17592
23  92.703 14733
23  85.956 13633
23    98.9 17592
24    92.8 17592
24  95.669 14950
24  91.495 13528
25   104.8 17592
25  92.791 13304
25   106.8 14684
26   104.2 17592
26 106.601 14656
26  96.572 13464
27  95.426 14684
27      98 17592
27  86.147 13303
28  98.903 13452
28    95.6 17592
28  80.855 14903
29 104.802 14948
29   106.5 17592
29 109.605 13536
30  92.983 13461
30 104.066 14929
30   103.9 17592
31  112.55 13298
31 127.739 14656
31   119.5 17592
32    97.1 17592
32  92.883 14948
32 101.927 13535
33   97.68 14991
33   97.21 13185
33   102.8 17592
34  98.784 13297
end
I want to create a plot to show the change in FEV1 with time (PartDat). I tried to use -xtline-, but since there are many observations the plot looks messy. Because of this I want to force the observations in to three groups, defined by the change in FEV1 from first to last observation. If I had data in wide format I would generate groups via a syntax along the lines of
Code:
gen group =.
replace group = 1 if FEV1_firstobs<80 & FEV1_lastobs>80
etc.
But I'm not sure how I could obtain the same thing with long data. I am helpful for any suggestions.

Best regards,
Sigrid