Hi:
You could try something like this:
For illustration, I'll use a data frame that was presented in a recent post
to the ggplot2 group. The poster wanted regressions by individual, but you
can add more than one grouping variable to the code I show below. It uses
the plyr package.
library(plyr)
res - function(x) resid(x)
ds_test$u - do.call(c, llply(mods, res))
I'd be a little careful with this, because there's no guarantee the
results will by ordered in the same way as the input (and I'd also
prefer ds_test$u - unlist(llply(mods, res)) or ds_test$u -
laply(mods, res))
In your case,
Hi there,
I have a huge data set with multiple firms years and other firm
characteristics. I want to run a regression on the dependent variable and other
explanatory variables and calculate the residual terms by grouping the firms in
same year and same industry.
What I want to do is to
3 matches
Mail list logo