Announcement

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

  • selecting of observation

    The dependent variable is "drowsy alert," which has (0,1, i.e., true and false). If the drowsy alert was 1, I must select the ten observations before and after the drowsy alert = 1. At the same time have to choose the other independent variables in the dataset. Here I gave the dataex also. Kindly provide the code for this query.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str34 trip_id float(date_only hour minute second) byte(drowsy_alert drowsy_state distraction_alert) float(ear mar yaw pitch roll ect xaccel yaccel zaccel speed) double(vehicle_heading vehicle_roll vehicle_pitch)
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  0 0 0 . .26159495 .10488752   9.833755 -.007736351   1.281107    66     -21.25     -8.25       1.75 55.88889         19531520.5            139644             181236
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  1 0 0 .  .2923845 .13211872  15.192163    2.168017  -1.725799    66        -13     -13.5         11 54.92857           19519165            129894             191413
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  2 0 0 .  .2698856  .2057476  12.211357  -.26977754   .7839724    66      -20.5        -5         18       54         19513456.5            119259             184503
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  3 0 0 .  .1410334 .14884625  -9.550273    .9932376 -1.7844672  69.6        -33      -5.5        -15 53.92857           19511344            171679             173385
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  4 0 0 .  .2341736  .2707371   5.658582  -1.4316282  -5.027289  75.5        -17      13.5          6 52.85714         19519336.5            120451             217256
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  5 0 0 .  .3921453  .4215508  22.867023   -4.930424  11.524553    73          .         .          .       52                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  6 0 0 . .27430817  .4158316   16.37205  -2.8127944   5.300074    73     -17.75        .5      10.75 51.88889        19500874.25          218040.5           215097.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  7 0 0 . .22260918  .2645781   5.658144  -1.6014143  4.0368366  72.7      -16.5      -5.5        -.5 50.92857           19477886            283781             221859
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  8 0 0 . .24859993 .14630066 -.27981547   -3.549987    5.71673  69.1       -3.5         9         23       50         19506509.5            309620             233374
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15  9 0 0 . .24456504 .09743039 -22.097445   -2.735345   6.255741    69          .         .          .       50                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 10 0 0 . .23017654 .26599184    2.80846   -2.790727   7.751978  69.9     -48.25      26.5        -45 49.05556           19586591            365703           236497.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 11 0 0 . .17542396 .34993625  4.7388763     2.38635   11.60719  71.7          .         .          .       48                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 12 0 0 .  .1699708  .3170712 -1.6041293   -.5707971   10.03791  77.1      -46.5      15.5     -40.25       48         19686527.5            483464           274485.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 13 1 0 .  .2040179 .22827093  -.3744239   -.4911259    10.1419  81.7        -18        14        -26 47.92857           19793780            499932             251562
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 14 0 0 .  .1949058   .387358  4.3735695   1.4345527  10.258253    83      -19.5        39        -23       47           19924487            516180             271229
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 15 0 0 .  .2084023  .3362749   5.256968   1.0152042  13.348603  81.8          .         .          .       47                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 16 0 0 .  .1957172 .26949826   3.636836     1.45551  14.190056  82.3     -22.75     20.25     -16.25 46.11111        20123894.75            585990           238665.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 17 0 0 . .22651637  .3325226    9.31177    .3203013  13.091666    83          .         .          .       45                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 18 0 0 .  .2166265 .20288393  -8.855104   -1.208915  9.2491865    83       -8.5     19.25          6       45        20375640.75          602814.5           263673.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 19 0 0 . .23600525 .17658007 -22.822866    1.490595   3.542607    83          .         .          .       45                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 20 0 0 . .19541045  .3648512   3.453619   .58232284  12.725134  83.2      -6.25     25.75       -7.5       45         20592229.5            596337           243884.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 21 0 0 .  .2170807  .3213577    3.86087    .7553483  16.527163  85.3         -4        24         -8       45           20724314            606802             239494
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 22 0 0 .  .4539464  .2003652  27.529934   -8.133792  13.813876    86  -28.57143 32.857143  -39.14286 44.11765 20830078.285714287 609131.1428571428 243275.14285714287
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 23 0 0 . .24837786  .3136371  13.174256  -1.0927061   9.261726  82.8        -16        27        -17       44           20976448            598684             234073
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 24 0 0 .  .1518656  .2786699   -2.60738  -2.9157314   8.699241  87.4 -10.333333 36.333332  -7.333333   43.875           21120873 616382.6666666666             242579
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 25 0 0 . .20012143  .3597954 -1.1575993   .11307554  11.013927  91.3          .         .          .       43                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 26 0 0 . .21875674  .2147948  1.4933323   1.3758967  15.038196    92       10.5     29.25      27.25       43         21301331.5            641288           252841.5
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 27 0 0 .  .2219151  .2452255  -2.693451    .9223409  13.644296    90       20.5      34.5         25       43           21439275            673674             239751
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 28 0 0 . .19028254  .2996015   6.188072  -1.2912436   2.638948  91.1         10      33.5          6       43           21550674            686097             249288
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 29 0 0 . .15832643  .3536414     2.5782   2.0347197   5.863254    96          .         .          .       43                  .                 .                  .
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 30 0 0 .  .1780591   .249856  -6.504279    .2654687   11.49474 102.7       4.25     36.25      12.25       43           21737222          681951.5             228921
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 31 0 0 . .21571487  .2549778  -8.947081   4.4906406  15.890085 102.6          9      43.5         31       43         21916523.5            682352             200989
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 32 0 0 .  .2247338   .188046  -14.46994    2.439215  16.341087   101      -12.5        27      -16.5       43         22012961.5            701737             193041
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 33 0 0 . .21663205  .3845354   2.794689   1.0883099  11.009171  95.5        -16        18        -21       43           22070170            671649             207719
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 34 0 0 . .25445595  .3110874  10.225467    1.181596   8.239151    91  -4.285714  38.28571 -2.4285715       43 22174617.714285713 667995.8571428572 192380.14285714287
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 35 0 0 . .23782673   .311669  2.3418067  -.18144536   9.358574  90.9       10.5      11.5          1       43           22328790            691570             166249
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 36 0 0 . .21112888  .3751125   6.196842    2.594663   4.890529    90        4.5        16         -2       43         22440568.5            631301             127427
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 37 0 0 .  .2188665 .27920684   3.899905    .5150943   8.726884    90        9.5        37       13.5       43           22578277            637336             152428
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 38 0 0 .  .2211208  .3459735   3.716146  -1.3937348   8.037429  89.7       30.5        20       32.5 43.14286         22699499.5            651508             169804
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 39 0 0 .  .2143183 .32984895    5.27142    1.369656   7.395338  84.8       61.5        53      104.5 43.85714           22811810            609807              95491
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 40 0 0 . .19828826  .2408743  -6.278976    .4599981  11.325143  85.1         58        77       99.5 42.14286           22926502            647621              97659
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 41 0 0 . .21126515 .26490375   -6.06607  -2.6722834    10.1228  87.7         32        47         21 42.92857         23019983.5            668880             132056
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 42 0 0 .  .1838314  .2959391   .7934436   -2.568547   8.628952  89.8         57      48.5       63.5 42.14286         23130427.5            708726             134267
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 43 0 0 .  .2061903  .3451482  2.1216118   -2.619731   7.180644  96.4         41      49.5         39       43         23219385.5            660779             110145
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 44 0 0 .  .2568975  .4231356   4.004512  -.18443733  10.312608    94         -1      34.5      -31.5       43           23314272            646662              77990
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 45 0 0 . .20405456 .48241445   8.346264   4.1488085   3.315349    92       12.5        25          0       43           23425351            617461              79384
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 46 0 0 .   .254646  .4545702   9.267327  -2.2069883  2.6314175    92       15.5        33        7.5 43.14286           23575582            613349              67580
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 47 0 0 .   .274574  .3208687   3.211967   -4.894969   11.55161    92       15.5      24.5        6.5       44           23715914            652905              36160
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 48 0 0 . .21753757 .18308824  -10.61236   -.8703377   12.40078  90.8         27         8       12.5 44.14286           23827093            602246              13269
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 49 0 0 . .26370782  .3593181  10.857687  -.31731755  11.367665  90.5       16.5        24         -4       45           23914789            545596               5388
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 50 0 0 .  .3631921  .4674791   24.11387  -2.3786485   12.89447    90         31      35.5       33.5       45           23988791            547636              20087
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 51 1 0 . .17022698  .2525452   2.205861    .4064422   7.379893  91.3       26.5      11.5         17 45.07143           24058841            528546             -45808
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 52 0 0 . .15218626  .3682833    3.87174  -1.9938624      2.633  97.4         .5       4.5      -34.5 46.14286           24132194            486375             -41367
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 53 0 0 .  .2204825  .4495031   5.289432   -.3495783   5.253512   100          0        15        -35       47           24188714            430929             -66565
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 54 0 0 .  .2319442 .39601955   2.496062   -1.570179   7.157054  97.3  22.857143 17.571428         11 47.11765 24221824.285714287 403020.4285714286 -67345.57142857143
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 55 0 0 . .28947076  .3805475  12.667027   -.7611481  2.0059383    97         31      10.5        2.5 48.07143           24214357            353206             -93082
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 56 0 0 .  .2470811  .4695797    9.22929   2.0037968   2.868182  94.5       22.5        10      -16.5 49.14286           24229804            291917             -89729
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 57 0 0 . .26693222  .3424955   8.338802   1.1559739   6.004776    92       12.5         1      -24.5 50.14286           24232128            297994            -113914
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 58 0 0 . .22178923  .3237866   7.952963    3.393435   1.406122  91.7          6      -4.5      -23.5       51           24228019            234434            -153445
    "1DC5Ox_1665659700000_1665662100000" 22931 11 15 59 0 0 .  .2287552  .4528119  11.749625    3.345068 -2.3251622  86.1        -16        18      -47.5 51.07143           24249564            161642            -177359
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  0 0 0 . .17002563  .3750592   5.856089  -2.0559719 -.47004575  84.9       17.5         6       -5.5 52.14286           24245257            197186            -113630
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  1 0 0 .  .2846077  .3307626  12.491036   1.1212417  -2.005997    86       46.5     -17.5       15.5       53         24226915.5            183755            -159860
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  2 0 0 . .14803462  .1646383  -17.00709   -3.192487 -1.1949906  86.6       20.5     -11.5        -40 53.14286           24243300            181450            -158778
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  3 0 0 . .04949474 .03831558     -47.69   -16.32625  -5.299152  83.4         28        -2        -13 54.14286           24250610            181404            -151170
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  4 0 0 . .15802236  .0761404  -21.64633   -8.853367  -.6509157  77.8         46         5       24.5    55.25         24259806.5            161664            -143572
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  5 0 0 . .22453004  .3792851   .5205294    -.324824  1.1189656  77.3       13.5       -14        -28 56.03333         24245862.5            191232            -173666
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  6 0 0 . .24648514  .3232301 -16.597944   2.2198648  -.4080891  77.7        -14       -18      -57.5       57         24218311.5            167410            -159591
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  7 0 0 . .20946504  .3174106   -5.69963    1.543767   5.244257    78        -29       2.5        -62       57         24190092.5            176075            -159211
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  8 0 0 . .20313257 .28274018  .57383835    2.718129   6.356605  78.1      -53.5       -10       -119       57         24159700.5            208657            -168966
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16  9 0 0 . .22285366  .2742978 -20.800354    3.865763  1.6840507    79         16       -13      -17.5 57.13334           24156283            196297            -131656
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 10 1 0 . .22265416  .4041688  1.2852304    .1692943  4.6598673  78.1         47        -7         48   58.125         24135650.5            192212            -132628
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 11 0 0 . .17497315  .3702598  -13.85421    4.852288   1.943379  77.3          7     -19.5         -3 59.05882           24094888            185847            -162338
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 12 0 0 . .22264963   .417946   9.464654   2.0535603  -1.387849  72.5         .5       2.5       -8.5       60         24100383.5            197415            -182730
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 13 0 0 . .26330477  .3217879  13.610577   2.0402613  1.0874406  68.3      -18.5      36.5        -67 60.07143         24212529.5            111667            -137282
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 14 0 0 . .19635795  .3563912   9.260855    1.831172   5.983105  68.1         -5      17.5        -40       61           24279998            154137            -141552
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 15 0 0 . .27725095  .4700382  16.910612     .840025   3.304726  68.9         18       9.5       12.5       61         24263559.5            132044            -130173
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 16 0 0 .  .4080403  .4433492  26.337254  -1.3251644  8.7962265  67.7         -3      12.5      -22.5 61.14286           24270879            154658            -145464
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 17 0 0 . .23853116  .4381853  11.964287   1.3270568   3.540229    67       -8.5         0      -36.5       62           24279155            159921            -165709
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 18 0 0 .  .3025555 .20873033  16.675344    .9552865   5.184547    67       22.5      -1.5        8.5 62.14286         24278947.5            147621            -131550
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 19 0 0 .  .3115392  .2410756  17.104212  -.09444484   5.425605    67         35         4         36       63         24273428.5            150397            -130394
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 20 0 0 .  .2047308   .425638   9.585443  -1.2413245    3.51603  67.7         10        -4       -9.5 63.14286           24259386            177923            -153196
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 21 1 0 . .24889807 .20797776    4.51803  -.22815064  4.1954947  65.7        1.5        -8        -27       64         24245377.5            154605            -153735
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 22 0 0 . .27222225  .0732126   7.796781    -7.81066  -3.205103    65         24       4.5         22 64.14286           24247787            162028            -148921
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 23 0 0 .  .2558658  .0433129  -.1880781  -12.955133   1.602965  64.7       45.5         0         62       65         24250884.5            170924            -135021
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 24 0 0 . .25361612 .21094537   7.722869   -7.866527  -1.651313  58.6       13.5         1         -1 65.14286         24265154.5            149070            -150617
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 25 0 0 .  .2747758  .4202225  12.299415    -1.83684   .9817063  54.7       -7.5        -3        -35       66           24264869            169762            -143221
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 26 1 0 .  .2963439  .4596061  21.786787  -1.4356556   4.205807  54.3        5.5       -10         -5 66.07143           24261157            165909            -161336
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 27 0 0 .  .1618526 .30767435 -2.4860494    .6118237  10.008888  60.2         41      -1.5       65.5       67         24256110.5            175231            -133756
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 28 0 0 .  .2178851 .27524307   6.640963    2.516882   3.187818  59.1       56.5         9        102 67.14286           24249741            140842            -147996
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 29 0 0 . .21482113  .3129495  -.4867027    1.398883   8.693101    56       16.5       9.5         31       68         24247899.5            171374            -158566
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 30 0 0 .  .2019479  .3460761  -.3090694    3.411276   1.790674  49.3        5.5       2.5       -5.5 68.14286           24242284            172076            -129936
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 31 0 0 . .20931497  .4135386   7.118306    4.804619  -.6693102    48         19       2.5       15.5       69         24261327.5            159471            -142771
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 32 0 0 .  .1687723  .3553153   8.218434   1.4818528    .770749  50.5        -17        -8      -34.5       69         24266247.5            167539            -151658
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 33 0 0 . .26448923 .21530387   9.596673   1.1949422   5.363333    54      -15.5        -9      -33.5 69.14286           24251262            165572            -103337
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 34 0 0 .  .2204515  .3622991  12.319243    .5798118  2.1983361    54         13       -.5        4.5       70         24239421.5            153064             -78767
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 35 0 0 .  .1850767 .36609745  18.346815  -.27092814 -1.2312596    54        7.5         0         -4 69.85714           24236017            146037             -41886
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 36 0 0 .  .2409731  .4728765    6.62096   2.4517076   .6740841  54.2        8.5         4       13.5       69         24242032.5            134042             -16920
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 37 1 0 . .15165496  .4528263 -3.8185675    4.996684   .8472676  55.1        2.5       5.5       28.5       69           24246980            119415              11243
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 38 0 0 .  .2071116  .3802488   7.266866    .8450368  2.1313004    56         10         2         47 68.85714           24247193            137370              23804
    "1DC5Ox_1665659700000_1665662100000" 22931 11 16 39 0 0 . .23549147 .23778476  2.2833993   1.4967924   5.304204  56.3       15.5      -9.5         36       68         24219567.5            135273              33560
    end
    format %td date_only

  • #2
    The downloadable command rangestat should be able to do that.

    First, combine the date and time variables into one date/time variable, which will be used to define the time interval:

    Code:
    gen long datetime = .
    replace datetime = mdyhms(month(date_only), day(date_only), year(date_only), hour, minute, second)
    format datetime %tc
    This datetime variable is in a unit of millisecond. So, if we need 10s before and after, we will set the interval as -10000 ms and +10000 ms. But first download and install rangestat.

    Code:
    ssc install rangestat, replace
    Then, try run this on your sample:

    Code:
    rangestat (max) drowsy_alert, interval(datetime -10000 10000)
    And if you have multiple IDs, use a by() option to confine the action to each ID, like:

    Code:
    rangestat (max) drowsy_alert, interval(datetime -10000 10000) by(trip_id)
    You'll see a new variable created at the end of the data set, whichever cases that are "1" would be the cases to keep. Validate the some results carefully and make sure they are correct. To learn more, use command:

    Code:
    help rangestat

    Comment


    • #3
      Originally posted by Ken Chui View Post
      The downloadable command rangestat should be able to do that.

      First, combine the date and time variables into one date/time variable, which will be used to define the time interval:

      Code:
      gen long datetime = .
      replace datetime = mdyhms(month(date_only), day(date_only), year(date_only), hour, minute, second)
      format datetime %tc
      This datetime variable is in a unit of millisecond. So, if we need 10s before and after, we will set the interval as -10000 ms and +10000 ms. But first download and install rangestat.

      Code:
      ssc install rangestat, replace
      Then, try run this on your sample:

      Code:
      rangestat (max) drowsy_alert, interval(datetime -10000 10000)
      And if you have multiple IDs, use a by() option to confine the action to each ID, like:

      Code:
      rangestat (max) drowsy_alert, interval(datetime -10000 10000) by(trip_id)
      You'll see a new variable created at the end of the data set, whichever cases that are "1" would be the cases to keep. Validate the some results carefully and make sure they are correct. To learn more, use command:

      Code:
      help rangestat

      don't consider about the time and dates, i have to select the observations on the float only. loop will helpful for my query can you give some ideas for to build a loop code

      Comment


      • #4
        Originally posted by sudharsan reddy View Post

        don't consider about the time and dates, i have to select the observations on the float only. loop will helpful for my query can you give some ideas for to build a loop code
        In that case, create a sequence variable and the use it instead for rangestat:

        Code:
        gen seq = _n
        rangestat (max) drowsy_alert, interval(seq, -10, 10)
        Loop will be the last thing I recommend, it will take much longer. But if you are only looking for loop, then disregard what I suggested and wait for someone who can help.
        Last edited by Ken Chui; 22 Feb 2023, 10:00.

        Comment

        Working...
        X