Background One of the key aspects of fair access to healthcare is access to affordable medications, which is essential for almost every government. Exploring and estimating the effects of the Social Determinants of Health (SDH) on affordability is an important step to clarify and picture the equity in health and targets for policy making. This paper attempts to estimate these effects on medication affordability in Iran. Methods We used data from the Iran Households Survey (IHS) in a 26-year period from 1997 to 2022. We developed a panel data econometric model to estimate the effects of Socioeconomic Determinants (SEDs) on medication expenses and three ratios, including: medication expense/ health costs, income, and all costs, as affordability indices. We employ Fixed Effect (FE) estimators, Random Effect (RE) estimators, Panel Tobit (PT) estimators, and Maximum Likelihood Estimators (MLE) for this purpose. Results the mean medication expenses for each household are about 1.45E + 07 IRR adjusted in 2021(1400 Persian calendar) inflation rate. The Concentration Index (CI) is about 0.12. The median of the medication expenses/ health expenses is about 33.5%. We don't realize that inequality for this ratio between provinces (CI = -0.01), increase prevalence of rare disease, age of households' head, increase the share of food and housing expenses, and increase family size can increase household expenses and financial burden. Instead of getting a transfer payment as a cash subsidy, having insurance can reduce medication costs. Conclusion This study uses provincial panel data to explore socioeconomic determinants of medication affordability, incorporating novel variables like rare disease prevalence, internet access, government support, and pharmacist population. Results show minimal inequality in medication costs among wealthier provinces, with no differences in the medication-to-health expense ratio. Older age, larger household size, and rare disease prevalence hinder affordability, while private insurance and government subsidies improve access. No significant correlations were found between affordability and national insurance or availability. Future research should investigate the causal mechanisms and occupational and educational differences.