Hi everyone,

I have a household-level panel data for two years. In the data, I also have the date on which the household was interviewed which I use to create a new variable distance. Distance takes the value from -59 to +60 with 0 representing if the household was interviewed during a specific festival and minus and plus values representing how far behind or ahead the household was interviewed with respect to the first day of the festival.

I want to create a graph that plots distance on the x-axis and the number of prayers offered on the y-axis. I used this,

sort distance
egen prayerma = mean(prayer), by(distance)
graph two line (prayerma distance), sort

this works but I am wondering if there is a way to smooth this further? I want the moving average for each person defined such that it's the average of (prayers on the distance value + prayer of 2 lagged distances).


I tried this (https://www.stata.com/support/faqs/s...nd-panel-data/) by Nic Cox but couldn't seem to make a smooth graph.

Any help on this will be highly appreciated.

Thanks

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input int(interview_date year) float(hhid distance) byte prayer
17362 2007 11769 -59 2
17362 2007 11823 -59 2
17363 2007 11917 -58 1
17364 2007 12007 -57 5
17365 2007 12200 -56 1
17366 2007 12447 -55 3
17368 2007 12573 -53 5
17369 2007 12674 -52 2
17370 2007 12858 -51 5
17371 2007 12946 -50 5
17371 2007 13068 -50 5
17372 2007 13092 -49 5
17372 2007 13111 -49 2
17373 2007 13449 -48 2
17373 2007 13316 -48 2
17375 2007 13557 -46 2
17375 2007 13598 -46 2
17376 2007 13761 -45 2
17377 2007 13916 -44 2
17378 2007 13993 -43 2
17379 2007 14263 -42 5
17380 2007 14294 -41 2
17382 2007 14506 -39 2
17383 2007 14794 -38 2
17383 2007 14800 -38 2
17384 2007 14901 -37 5
17385 2007 15118 -36 4
17386 2007 15346 -35 5
17386 2007 15325 -35 2
18096 2009  3004 -34 5
17387 2007 15461 -34 1
18097 2009  4490 -33 5
17389 2007 15655 -32 5
17389 2007 15678 -32 1
17390 2007 15775 -31 2
17390 2007 15813 -31 2
18100 2009 21524 -30 2
18100 2009  2393 -30 5
18101 2009  3275 -29 3
17392 2007 16246 -29 2
17392 2007 16258 -29 2
17393 2007 16460 -28 2
18102 2009 10573 -28 2
17393 2007 16469 -28 2
18103 2009  3873 -27 5
17394 2007 16697 -27 2
17394 2007 16671 -27 3
18104 2009  7424 -26 5
18104 2009   477 -26 5
18105 2009 14125 -25 4
17396 2007 16834 -25 5
18105 2009  1593 -25 2
17396 2007 16848 -25 5
18106 2009  2832 -24 2
17397 2007 17033 -24 2
17397 2007 17020 -24 2
17397 2007 16949 -24 5
17398 2007 17243 -23 1
17398 2007 17132 -23 2
17398 2007 17124 -23 3
17399 2007 17367 -22 1
18108 2009  2986 -22 2
17399 2007 17390 -22 2
17399 2007 17313 -22 2
18109 2009   575 -21 2
18109 2009 15446 -21 5
17400 2007 17607 -21 2
18109 2009 21175 -21 2
17401 2007 17857 -20 2
18110 2009  2665 -20 5
18110 2009 14695 -20 2
18110 2009 15164 -20 5
17401 2007 17769 -20 2
18111 2009  2409 -19 5
18111 2009  4098 -19 1
18111 2009 11442 -19 1
17403 2007 18053 -18 5
18112 2009 12390 -18 2
18112 2009  2534 -18 1
18112 2009  9266 -18 2
18113 2009 12302 -17 3
17404 2007 18325 -17 1
18113 2009  4442 -17 2
18113 2009  7335 -17 5
18113 2009 22923 -17 4
17405 2007 18433 -16 2
18114 2009 17022 -16 4
17405 2007 18432 -16 2
17405 2007 18428 -16 5
17406 2007 18585 -15 2
17406 2007 18577 -15 5
18115 2009  4190 -15 5
17406 2007 18619 -15 2
17407 2007 18764 -14 2
17407 2007 18747 -14 1
18117 2009 13040 -13 2
18117 2009  9338 -13 2
18117 2009  1402 -13 2
18118 2009 11087 -12 2
17409 2007 18881 -12 3
end
format %td interview_date
label values prayer muslim_prayer
label def muslim_prayer 1 "Never", modify
label def muslim_prayer 2 "Occasionally", modify
label def muslim_prayer 3 "1-2 times a day", modify
label def muslim_prayer 4 "3-4 times a day", modify
label def muslim_prayer 5 "5 Times a day", modify