[R] lmList

Daniel Malter daniel at umd.edu
Wed Jun 24 18:44:40 CEST 2009


Cecilia, this is impossible to tell from the information you provide. The
simulated data below...

##START
year=rep(1:10,10)
year.fe=rep(rgamma(10,10,2),10)
firm.fe=rep(rnorm(10,0,3),each=10)
x=rnorm(100,0,3)
e=rnorm(100,0,3)
y=10+firm.fe+year.fe+x+e
newdata=data.frame(y,x,e,firm,year,firm.fe,year.fe)

reg=lm(y~x,subset=year%in%c(1))
summary(reg)


library(nlme)
reg=lmList(y~x|year,data=newdata)
summary(reg)
##END


...produces the exact same estimates in lm (base) and in lmList (nlme).
Thus, the mistake lies most probably somewhere in your data setup. For
example, sometimes the data you provide to lmList can differ because in lm
the data may be taken from the global environment, whereas you explicitly
provide the dataset in lmList. If they do not perfectly coincide, you would
naturally see differences. Therefore, provide the explicit dataset to lm
too. (for the above example: reg=lm(y~x,subset=year%in%c(1),data=newdata).
If you still observe differences, you have to be more specific and provide
your data and code...

Hope that helps,
Daniel

-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Cecilia Carmo
Gesendet: Wednesday, June 24, 2009 8:23 AM
An: r-help at r-project.org
Betreff: [R] lmList

Hi R-helpers:

I have a function f<-y~a+b.x and my data is an unbalanced panel data (a
dataframe with columns: firm,year,y,x). I need to run that regression by
year. I started to subset the data by year and run the lm () function, but I
asked R help how to perform this regressions at once. One of the suggestions
was to run lmList (y ~ a + b.x  | year, 
) but the coefficients that I
obtain are different from those I have before. Someone could explain me why?

Thank you,
Cecília Carmo (Universidade de Aveiro - Portugal)

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list