0

I have a whole data frame df whose columns are y1, y2,..yn, x, z. The first several columns are y, and the last two are X and Z (instrumental variable) So I am trying to do many instrumental regressions. Them should look like reg1 <- ivreg(y1~ x|z, data = df) ... regn<- ivreg(yn~ x|z, data = df)

and I want the see the result, hopefully put the coefficients all in a table.

lilgrass
  • 13
  • 3
  • Hi Eveline and welcome to SO ! You will get better feedback and answers by providing a reproducible example. You will find all the means to so at [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example): . There are some nice examples of what you want to do at [econometrics-with-r.org/ivr.html](https://www.econometrics-with-r.org/ivr.html). Putting all the coefficients in one table might cause readability issue though. – cbo Oct 24 '22 at 08:45
  • Maybe sth like this? `sapply(1:(length(df)-2),function(a) {reg <- ivreg(df[,a] ~ df[,"x"]|df[,"z"]) ; reg$coefficients})` – maydin Oct 24 '22 at 08:53
  • What is the difference between what you are proposing and what you want to obtain? – socialscientist Oct 24 '22 at 09:20

0 Answers0