Announcement

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

  • Line graph of the mean of all observations

    Hello all,

    I have data that have three variables: vehicle id, speed_kmh, and Time_of_Travel.

    I am seeking your help with a code that is capable of calculating the mean of all observations at each travel time (or fixed distance based on the x-axis unit) and then creating a line graph that shows the trend of the observation along with the mean of all observations. An example is shown below for speed vs distance along with my data.

    I am using the following code:

    xtline speed_kmh , i( vehicleid ) t( timeoftravelall ) overlay leg(off)

    if possible, a code works for both cases 1- speed vs time and 2- speed vs distance.

    Thank you so much.


    Click image for larger version

Name:	Graph_speed_vs_time.png
Views:	2
Size:	126.1 KB
ID:	1672474 Click image for larger version

Name:	Screenshot 2022-07-06 170713.png
Views:	4
Size:	581.7 KB
ID:	1672475
    Vehicle ID Speed_kmh Time_of_Travel
    1 80.99 0.00
    1 80.99 0.50
    1 80.29 1.00
    1 78.92 1.50
    1 76.87 2.00
    1 75.50 2.50
    1 74.10 3.00
    1 72.67 3.50
    1 70.56 4.00
    1 69.17 4.50
    1 67.75 5.00
    1 66.27 5.50
    1 64.06 6.00
    1 62.59 6.50
    1 61.24 7.00
    1 60.02 7.50
    1 58.21 8.00
    1 57.03 8.50
    1 55.63 9.00
    1 54.03 9.50
    1 51.63 10.00
    1 50.06 10.50
    1 48.23 11.00
    1 46.13 11.50
    1 42.99 12.00
    1 40.90 12.50
    1 39.02 13.00
    1 37.38 13.50
    1 34.90 14.00
    1 33.25 14.50
    1 31.56 15.00
    1 29.84 15.50
    1 27.26 16.00
    1 25.53 16.50
    1 23.74 17.00
    1 21.87 17.50
    1 19.07 18.00
    1 17.21 18.50
    1 15.38 19.00
    1 13.58 19.50
    1 10.89 20.00
    1 9.10 20.50
    1 8.04 21.00
    1 7.72 21.50
    1 7.24 22.00
    1 6.92 22.50
    1 6.26 23.00
    1 5.28 23.50
    1 3.81 24.00
    1 2.83 24.50
    1 2.37 25.00
    1 2.41 25.50
    1 2.49 26.00
    1 2.54 26.50
    1 2.31 27.00
    1 1.81 27.50
    1 1.08 28.00
    1 0.59 28.50
    1 0.34 29.00
    1 0.34 29.50
    1 0.34 30.00
    2 89.11 0.00
    2 89.11 0.50
    2 88.32 1.00
    2 86.75 1.50
    2 84.43 2.00
    2 82.90 2.50
    2 81.78 3.00
    2 81.09 3.50
    2 80.08 4.00
    2 79.43 4.50
    2 78.11 5.00
    2 76.14 5.50
    2 73.21 6.00
    2 71.28 6.50
    2 69.13 7.00
    2 66.76 7.50
    2 63.26 8.00
    2 60.94 8.50
    2 58.31 9.00
    2 55.34 9.50
    2 50.88 10.00
    2 47.91 10.50
    2 44.91 11.00
    2 41.89 11.50
    2 37.37 12.00
    2 34.35 12.50
    2 31.19 13.00
    2 27.91 13.50
    2 22.98 14.00
    2 19.69 14.50
    2 17.45 15.00
    2 16.25 15.50
    2 14.46 16.00
    2 13.27 16.50
    2 12.21 17.00
    2 11.27 17.50
    2 9.86 18.00
    2 8.92 18.50
    2 7.94 19.00
    2 6.94 19.50
    2 5.43 20.00
    2 4.43 20.50
    2 3.63 21.00
    2 3.03 21.50
    2 2.14 22.00
    2 1.54 22.50
    2 1.11 23.00
    2 0.84 23.50
    2 0.47 24.00
    2 0.23 24.50
    2 0.12 25.00
    2 0.12 25.50
    2 0.12 26.00
    3 86.50 0.00
    3 86.50 0.50
    3 85.87 1.00
    3 84.65 1.50
    3 82.85 2.00
    3 81.67 2.50
    3 80.90 3.00
    3 80.54 3.50
    3 80.05 4.00
    3 79.74 4.50
    3 78.74 5.00
    3 77.04 5.50
    3 74.51 6.00
    3 72.85 6.50
    3 70.71 7.00
    3 68.09 7.50
    3 64.22 8.00
    3 61.65 8.50
    3 58.48 9.00
    3 54.67 9.50
    3 48.96 10.00
    3 45.16 10.50
    3 41.55 11.00
    3 38.13 11.50
    3 33.01 12.00
    3 29.59 12.50
    3 26.75 13.00
    3 24.49 13.50
    3 21.10 14.00
    3 18.84 14.50
    3 16.55 15.00
    3 14.24 15.50
    3 10.77 16.00
    3 8.46 16.50
    3 7.19 17.00
    3 6.96 17.50
    3 6.61 18.00
    3 6.38 18.50
    3 5.62 19.00
    3 4.33 19.50
    3 2.39 20.00
    3 1.10 20.50
    3 0.45 21.00
    3 0.45 21.50
    3 0.45 22.00

    Attached Files
Working...
X