[R] lmList

Daniel Malter daniel at umd.edu
Wed Jun 24 22:18:53 CEST 2009


As I said, the example works. So for simulated data it works, which means
that for correctly provided data, it should work as well.

year%in%c(1) means for all years in the vector. In this case, it is
identical to year==1. However, the option I use is extendable since you
could write year%in%c(1,3,7) for example. So it would run the regression on
the data for years 1,3, and 7. This should have nothing to do whether your
analysis gives the same result as in one-by-one regressions.

Again, the best advice is that you should check that the data the
regressions are run on are absolutely identical. If they are, the results
should be the same.

Daniel



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

-----Ursprüngliche Nachricht-----
Von: Cecilia Carmo [mailto:cecilia.carmo at ua.pt] 
Gesendet: Wednesday, June 24, 2009 1:17 PM
An: Daniel Malter
Betreff: Re: AW: [R] lmList

Well it doesn´t work with my example, but I will do some more experiences.
Could you tell me what means year%in%c(1), more specific c(1). Instead of it
I usually write subset=data$year==2000, and I run the regressions one by one
for each year.

Thanks
Cecília


Em Wed, 24 Jun 2009 12:44:40 -0400
  "Daniel Malter" <daniel at umd.edu> escreveu:
> 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