Skip to content
Prev 30893 / 398506 Next

To create a Panel and run a Pooled OLS

Dear Sophie,

I think that the real question here is what you're trying to do; if you 
simply want to stack one cross section on top of the other, the simplest 
way to do that is with cbind.

To understand why your merge failed, just look at the merged data frame:

     > 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")
     > 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

On the other hand, here's what you get with rbind:

     > Panel <- rbind(Cross1, Cross2)
     > Panel
     i Y X1
     1  1 3  2
     2  2 2  3
     3  3 2  4
     11 1 2  5
     22 2 3  6
     33 3 1  7

Fitting a regression to this data frame works fine; either  OLS <- 
lm(Panel$Y ~ Panel$X1)  or  OLS <- lm(Y ~ X1, data=Panel)  will do the 
trick, although the latter is clearer, I think.

I hope that this helps,
  John
At 05:02 AM 4/21/2003 +0200, Sophie Langenskiold wrote:
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox