How to handle potential endogeneity in a ppml gravity using orthogonal residuals and lagged instruments?

I'm working with dyadic panel data and estimating a Poisson Pseudo Maximum Likelihood (PPML) gravity model. Two variables I suspect to be endogenous (let's call them var1 and var2) are initially regressed on several institutional predictors using OLS. I then use the residuals in my gravity model.

After that, I construct lagged versions of the residuals to serve as instruments. Here’s the general structure of my code (simplified and anonymized):

Step 1: Regress var1 and var2 on instruments

ols_1 <- feols(var1 ~ inst1 + inst2 + inst3 + inst4, data = my_data)

ols_2 <- feols(var2 ~ inst1 + inst2 + inst3 + inst4, data = my_data)

Step 2: Extract residuals

my_data$resid_1 <- resid(ols_1)

my_data$resid_2 <- resid(ols_2)

Step 3: Use residuals in a PPML gravity model

ppml_orthogonal <- fepois(trade_flow ~ dist + resid_1 + resid_2 + control1 + control2 + ... |time + exporter + importer + exporter^importer,data = my_data)

Step 4: Create lagged instruments

my_data <- my_data %>% group_by(exporter, importer) %>% arrange(year) %>%mutate( lag_resid_1 = lag(resid_1), lag_resid_2 = lag(resid_2) ) %>% ungroup()

Step 5: First-stage regressions for IV approach

fs_1 <- feols(resid_1 ~ lag_resid_1, data = my_data)

fs_2 <- feols(resid_2 ~ lag_resid_2, data = my_data)

Step 6: Use fitted residuals as instruments in final PPML

my_data$resid_fs_1 <- resid(fs_1)

my_data$resid_fs_2 <- resid(fs_2)

ppml_iv <- fepois(trade_flow ~ dist + resid_fs_1 + resid_fs_2 + control1 + control2 + ... |time + exporter + importer + exporter^importer,data = my_data)

My assumption is that var1 and var2 (e.g. representing economic performance) may be endogenous, so I use their orthogonal residuals and then instrument those residuals using their lags.

My Questions :

Is this a valid strategy to handle potential endogeneity in var1 and var2?

Are there better or more accepted practices for instrumenting residuals before including them in PPML models?

Does this qualify as a valid two-stage IV-PPML approach?

Any references or suggestions would be highly appreciated!