Search code examples
rregressionstataspss

Multiple regression equations


Is there a way that I can run 100 different regressions together and get the output of all equations together in a table format? Any software will work. I need to find growth rates of 100 commodities using log-linear model. So I have 100 equations with dependent variable being ln(value of exports) and independent variables being time (0 to 30). So running regression individually for 100 equations is lot of manual work. I just require the coefficients of t for all the 100 equations. Any way to shorten the time spent doing so?


Solution

  • For example, assuming you have a data frame commodity_data in R with each commodity as a different column:

    n <- ncol(commodity_data)
    logslopes <- numeric(n)
    tvec <- 0:(nrow(n)-1)
    for (i in 1:n) {
      m <- lm(log(commodity_data[,i]) ~ tvec)
      slope <- coef(m)["tvec"]
      logslopes[i] <- slope
    }
    

    There are slicker ways of doing this, but this one should work fine.