A special case of GMM estimation in R I want to estimate the forward looking version of the Taylor rule equation using the iterative nonlinear GMM:

I have the data for all the variables in the model, namely  (inflation rate),  (unemployment gap) and  (effective federal funds rate) and what I am trying to estimate is the set of parameters ,  and .
Where I need help is in the usage of the gmm() function in the {gmm} R package. I 'think' that the parameters of the function that I need are the parameters:
gmm(g, x, type = "iterative",...)

where g is the formula (so, the model stated above), x is the data vector (or matrix) and type is the type of GMM to use.
My problem is with the data matrix parameter. I do not know the way in which to construct it (not that I don't know of matrices in R and all the examples I have seen on the internet are not similar to what I am attempting to do here. Also, this is my first time using the gmm() function in R. Is there anything else I need to know?
 A: I was able to find an answer to this question, which I posted almost 8 years ago. The x argument is meant for a matrix of instruments for the model. The instruments can be any variable, which theory or common sense say it belongs to the model. For this example, let's use the lag of the interest rate, the output gap and the inflation rate as instruments. Note that I download the data with the fredr package. The code below is reproducible; however, a free API key which can be obtained from the FRED website is needed (https://fred.stlouisfed.org/).
# Load packages
library(gmm)
library(dplyr)
library(purrr)
library(fredr)

# Set FRED API key

# Reference codes for datasets
ids <- c(
  "DGS3MO", # 3-month treasury rate (interest rate)
  "CPALTT01USM657N", # inflation rate
  "GDPC1", # Real GDP
  "GDPPOT" # Potential GDP
)

# Download datasets and create model variables

dat <- map(ids, ~ fredr_series_observations(.x, frequency = "q", aggregation_method = "eop")) %>%
  reduce(inner_join, by = "date") %>%
  select(-matches("series")) %>%
  setNames(c("date", "int", "inf", "rgdp", "pgdp")) %>%
  mutate(
    og = rgdp - pgdp,
    int_lag1 = dplyr::lag(int, 1),
    inf_lead1 = dplyr::lead(inf, 1),
    across(.cols = c(int, inf, og), 
           .fns = ~ dplyr::lag(.x, 1), 
           .names = "{.col}_lag1"),
    across(.cols = c(int, inf, og), 
           .fns = ~ dplyr::lag(.x, 2), 
           .names = "{.col}_lag2")
  ) %>%
  tidyr::drop_na()

# Create matrix of instruments

instruments <- dat %>%
  select(matches("(int|inf|og)\\_lag\\d{1}"))


# Fit a GMM model

mod <- gmm(
  g = int ~ inf_lead1 + og + inf_lag1,
  data = dat,
  x = instruments,
  type = "iterative"
)

summary(mod)

Call:
gmm(g = int ~ inf_lead1 + og + inf_lag1, x = instruments, type = "iterative", 
    data = dat)


Method:  iterative 

Kernel:  Quadratic Spectral(with bw =  1.91839 )

Coefficients:
             Estimate     Std. Error   t value      Pr(>|t|)   
(Intercept)   2.8276e+00   6.0192e-01   4.6976e+00   2.6323e-06
inf_lead1     5.3314e+00   1.8394e+00   2.8984e+00   3.7506e-03
og            5.5637e-03   1.0989e-03   5.0631e+00   4.1254e-07
inf_lag1     -1.2443e-01   5.7749e-01  -2.1547e-01   8.2940e-01

J-Test: degrees of freedom is 3 
                J-test      P-value   
Test E(g)=0:    4.5763e+01  6.3694e-10

Initial values of the coefficients
(Intercept)   inf_lead1          og    inf_lag1 
2.451980475 8.326496191 0.004320203 1.543310038 
````

