Correcting for a covariate in a Kaplan-Meier curve I wish to perform a drug survival analysis. Specifically, I wish to see if there are sex differences in drug survival in my dataset. One advantage of my dataset is that it is a large cohort, since fifteen different countries contributed to its creation. However, this also results in statistically significant heterogeneity. One option for me would be to create a KM-curve and stratify by country because of this heterogeneity. However, I was wondering if an option exists to "correct" for countries inside the KM-curve.
Would love to hear if something like this is possible and/or whether this is wise.

Frank's answer mentions stratification, and that was the route I was pursuing when I suggested you move your earlier closed question to CV.com. As I suggested in a comment you did get an answer from a smarter respondent than I am. If you ran separate models on each country (simple to do in R) you might get a better idea of the distribution of estimates. I would also think that using age as a covariate would be essential. Frank's text "Regression Modeling Strategies" has a wealth of material on dealing with non-linear effects of covariates.
Your question had been how to build a model with weighting in a manner that might recognize the heterogeneity. Here is a stratified model build based on the tiny test set you offered
library(survival)
gender <- as.factor(c("Female", "Male", "Female", "Male", "Male", "Male", "Female", "Female", "Female", "Male"))
country <- as.factor(c("US", "US", "GB", "GB", "GB", "US", "GB", "US", "GB", "US"))
time <- c(5, 10, 12, 15, 20, 9, 14, 18, 24, 20)
event <- c(1, 1, 1, 1, 1, 0, 0, 1, 0, 1)
df <- data.frame(gender, country, time, event)

km.model2
Call:
coxph(formula = Surv(time = time, event = event) ~ gender + strata(country), 
    data = df)

              coef exp(coef) se(coef)      z    p
genderMale -0.2321    0.7929   0.8327 -0.279 0.78

Likelihood ratio test=0.08  on 1 df, p=0.7807
km.model2 <- survfit(Surv(time = time, event = event) ~ gender +strata(country), data = df)

The usual assumptions about Cox models with a simple continuous covariate apply, but here two separate models have been constructed and a weighted "average" of their coefficients have been returned. This will not account for all forms of non-proportionality. For testing you might also need to assess whether the effect is constant over time as the model assumes using the cox.zph function. Therneau & Gambsch's text "Modeling Survival Data" has an excellent chapter.
