Skip to content

Instantly share code, notes, and snippets.

@tony91782
Created May 29, 2011 05:14
Show Gist options
  • Save tony91782/997494 to your computer and use it in GitHub Desktop.
Save tony91782/997494 to your computer and use it in GitHub Desktop.
ivboot <- function(sec,fir,data,boots=500){
dat <- data
sec <- as.formula(sec)
fir <- as.formula(fir)
thisiv <- iv(sec, fir,data)
booter <- function(dat,i){
coef(iv(sec,fir,data=dat[i,]))
}
boot_coef <-coef(thisiv)
myboot <- boot(dat, booter, R=boots,stype="i")
thisiv$second$coefficients[,2] <- sd(myboot$t)
thisiv$second$coefficients[,3] <- thisiv$second$coefficients[,1]/thisiv$second$coefficients[,2]
thisiv$second$coefficients[,4] <- 2*pnorm(-abs(thisiv$second$coefficients[,3]))
colnames(thisiv$second$coefficients) = c("Estimate", "Std. Error", "z value", "Pr( >|z|)")
return(thisiv)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment