Created
May 1, 2011 20:14
-
-
Save tony91782/950821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -------------------------------------- ## | |
## R Tutorial on Robust Standard Errors ## | |
## Author: Tony Cookson ## | |
## -------------------------------------- ## | |
## Read Data | |
library(foreign) | |
ed = read.dta("C://R//edudat2.dta") | |
## Obtain regression object | |
educ.lm = lm(log(wage)~gender + educ + pareduc, data=ed) | |
## Summarize Output Assuming Homoskedasticity | |
summary(educ.lm) | |
## Need to load the car library | |
library(car) | |
## If you don't have car installed you'll need to install it | |
## Use this command: | |
## install.packages("car", dependencies = TRUE) | |
## Then, run the library command library(car) | |
## Robust Standard errors | |
summaryR(educ.lm) ## Special Function written by John Fox | |
## Can Specify Type of Heteroskedasticity correction | |
summaryR(educ.lm, type="hc0") ## White SE | |
summaryR(educ.lm, type="hc1") ## Stata's Default | |
summaryR(educ.lm, type="hc2") ## Unbiased under homoskedasticity | |
summaryR(educ.lm, type="hc3") ## Default (conservative) | |
## Test using linearHypothesis | |
linearHypothesis(educ.lm, "educ+pareduc =1", white.adjust="hc3") | |
linearHypothesis(educ.lm, "educ+pareduc =1", white.adjust="hc0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment