Abstract: Highlights•Introduced a new model in medication recommendation, StratMed.•Proposed a novel data stratification method to mitigate the sparsity of medical datasets.•Developed an innovative dual-graph structure to represent the safety and precision of medications on the same level.•StratMed outperforms other models in various sparse scenarios.•StratMed achieves a balance between safety and precision, surpassing state-of-the-art baselines in comprehensive evaluations.