I'm currently running a series of regressions on a data set consisting of 72,000 observations with roughly 20 variables for each observation. One of these variables consists of 56 names and i want to run a regression for each name. I imagine I would create a for loop for this however I am a little inexperienced working with data sets of this size.
The variable containing the name is not in the regression.
NAME : variable I want to run a for loop for to run regressions for each name.
My Code:
my.mods = lapply(s.dat, FUN = function(x) {
lm(log(TM+1000) ~ log(Inc+1) + log(Slip_sq_K+1) +
log(Ten+1) + log(HF+1) + log(BroP+1) + log(B+1) +
log(sian+1) + log(H_+1) + log(C_65+1) + log(D+1) +
log(TIP+1) + log(p+1) + log(X34itP+1) + log(FGK+1) +
log(X19tP+1) + log(X2nitP+1) + log(Car_AloneP+1) +
log(CaoledP+1) +log(PTsP+1) + log(Gy+1) +
log(OthemeansP+1) + log(HP+1) + log(Coi+1) +
log(electr) + log(Na+1),
data = x, na.action=na.exclude)
} )
Thanks!
I prefer to work without loops if possible and I found this page really helpful. It shows how you can use a model within a plyr function and get a table with all the important parameters back from it.