fork download
  1. makeData <- function(){
  2. id <- rep(1:100, each=10)
  3. a <- rep(rnorm(100), each=10)
  4. x <- rnorm(1000) + a
  5. u <- 2*rnorm(1000) + 2*a
  6. y <- x + u
  7. return(data.frame(y=y,x=x,id=id))
  8. }
  9. crossSectionEst <- function(){
  10. i <- seq(5, 95, 10)
  11. m <- sapply(
  12. 1:1000,
  13. function(x){
  14. df <- makeData()
  15. df.cs <- df[i,1:2]
  16. est <- summary(lm(df.cs))$coefficients[2]
  17. return(est)
  18. }
  19. )
  20. return(mean(m))
  21. }
  22. print(crossSectionEst())
Success #stdin #stdout 1.42s 179584KB
stdin
Standard input is empty
stdout
[1] 2.037128