Looping through regressions

I am trying to loop through a regression where the dependent variable is in logarithmic form and the independent variable is years which is in linear form. I want to store the growth rates (the antilogarithm of the estimated regression coefficient minus 1) in a dataframe. I want to do this for several entities. I have stored data for each entity as a dataframe in a list. When I try the code below for one entity, it works:

reg1 <- lm(log(var1) ~ year, data=lst[[1]] )
growth_rate[1,1] <- (exp(coef(reg1[2]-1)*100)

Now I want to do this for several entities (I have 32 entities). Data on var1 for each entity is stored as a dataframe in list. So if I write a for loop, I could use lst[[i]] but I am not sure how to index the regression output. I tried the following but it doesn't work:

for (i in 1:32){
 reg[i] <- lm (log(var1) ~ year, data=lst[[i]])
 growth_rate[1:32,1] <- (exp(coef(reg[i]))[2] - 1)*100
}

Any help would be really appreciated.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.