Skip to content
Prev 260448 / 398502 Next

regression coefficient for different factors

First you have to create something (e.g., a list) that holds your output:

mylist<-NULL

Then you loop through the levels of c and run a regression of a onto b
(no need to include c anymore because c will have zero variance within
each level of c):
for(i in levels(c)){
  temp.data<-mydataset[mydataset$c %in% i]
  mylist[[i]]<-lm(a ~  b, data=temp.data)
}

Once you are done - you can write another loop (this time across all
elements of mylist - that will have as many elements as there are
levels in c) and extract the coefficients.
Dimitri


On Fri, May 20, 2011 at 9:57 AM, Francesco Nutini
<nutini.francesco at gmail.com> wrote: