Hello,
I have a dataset containing monthly aggregated mortality rates for a specific (not very dangerous) procedure over a 10-year period. My goal is to create a plot that effectively illustrates the general trend over time, without displaying the individual data points, as the final visualization will be used for a lecture (but I have included the scatter plot for clarity here).
I have considered using locally weighted regression (LOWESS) or local polynomial smoothing (lpoly), but I’ve noticed some irregularities at the tails when using lpoly. Given my objective, would either of these methods be appropriate, or is there a better approach for producing a smooth, reliable trend line?
I appreciate any insights or alternative recommendations.
Thank you!

I have a dataset containing monthly aggregated mortality rates for a specific (not very dangerous) procedure over a 10-year period. My goal is to create a plot that effectively illustrates the general trend over time, without displaying the individual data points, as the final visualization will be used for a lecture (but I have included the scatter plot for clarity here).
I have considered using locally weighted regression (LOWESS) or local polynomial smoothing (lpoly), but I’ve noticed some irregularities at the tails when using lpoly. Given my objective, would either of these methods be appropriate, or is there a better approach for producing a smooth, reliable trend line?
I appreciate any insights or alternative recommendations.
Thank you!
Code:
clear
input int admitmonth float monthly_mortality
622 0
623 0
624 0
625 0
626 0
627 0
628 0
629 0
630 0
631 0
632 .16666667
633 .2857143
634 0
635 0
636 0
637 0
638 0
639 0
640 0
641 0
642 0
643 0
644 0
645 0
646 0
647 0
648 0
649 0
650 0
651 0
652 0
653 0
654 .125
655 0
656 0
657 0
658 0
659 0
660 0
661 0
662 0
663 0
664 0
665 0
666 0
667 0
668 0
669 .14285715
670 0
671 0
672 0
673 0
674 0
675 0
676 0
677 0
678 0
679 0
680 0
681 0
682 .16666667
683 0
684 0
685 0
686 0
687 0
688 0
689 0
690 0
691 0
692 0
693 0
694 .125
695 0
696 0
697 0
698 0
699 0
700 .25
701 0
702 0
703 0
704 0
705 0
706 0
707 0
708 0
709 0
710 0
711 0
712 .16666667
713 .14285715
715 0
716 0
717 0
718 0
719 0
720 0
721 0
722 0
723 0
724 0
725 0
726 0
727 0
728 0
729 0
730 0
731 0
732 0
733 0
734 0
735 0
736 0
737 0
738 .25
739 0
740 .2
741 0
742 0
743 0
end
format %tm admitmonth
twoway lpoly monthly_mortality admitmonth, color(maroon%10) degree(4) || ///
scatter monthly_mortality admitmonth ///
, ///
scheme(uncluttered) ///
xtitle("Year") ytitle("In-hospital mortality [%]", margin(vsmall)) ///
tlabel(624(12)744, format("%tmCY")) ///
xlabel(, labsize(small)) ///
ylabel(0(0.05)0.3, labsize(small)) ///
legend(off) ///
graphregion(margin(l-1 r+3)) ///
title("Monthly mortality - lpoly") ///
name(lpoly, replace)
twoway lowess monthly_mortality admitmonth, color(maroon%10) || ///
scatter monthly_mortality admitmonth ///
, ///
scheme(uncluttered) ///
xtitle("Year") ytitle("In-hospital mortality [%]", margin(vsmall)) ///
tlabel(624(12)744, format("%tmCY")) ///
xlabel(, labsize(small)) ///
ylabel(0(0.05)0.3, labsize(small)) ///
legend(off) ///
graphregion(margin(l-1 r+3)) ///
xtitle("Year", margin(medsmall) size(medium)) ///
ylabel(0(0.05)0.3, labsize(small)) ///
ytitle("In-hospital mortality [%]", margin(medsmall) size(medium)) ///
title("Monthly mortality - lowess") ///
name(lowess, replace)

Comment