[R] To create a Panel and run a Pooled OLS

Thomas Lumley tlumley at u.washington.edu
Mon Apr 21 05:31:32 CEST 2003


On Mon, 21 Apr 2003, Sophie Langenskiold wrote:

> I appreciate your help a lot. Unfortunately, none of your
> recommendations work. I have written a small program to illustrate my
> problems. I hope there is a solution...
>
> Cross1 <- data.frame(i=c(1,2,3),Y=c(3,2,2),X1=c(2,3,4))
> Cross2 <- data.frame(i=c(1,2,3),Y=c(2,3,1),X1=c(5,6,7))
> Panel <- merge(Cross1,Cross2,by="i")
> OLS <- lm(Panel$Y~Panel$X1)
>

I think your problem is with the merge() statement. The Panel dataframe
looks like
> Panel
  i Y.x X1.x Y.y X1.y
1 1   3    2   2    5
2 2   2    3   3    6
3 3   2    4   1    7

so it doesn't have X1 or Y variables.

The solution depends on what you want, but my guess is that you need
  Panel<-rbind(Cross1,Cross2)
  lm(Y~X1,data=Panel)

Or perhaps
   Panel<-rbind(cbind(Cross1,time=1),cbind(Cross2,time=2))
   lm(Y~X1,data=Panel)


	-thomas



More information about the R-help mailing list