I am trying to replicate the behavior of STATA's Breusch-Pagan test following running a weighted least squares regression.
This code gives the same result (3.81) as the following code in R (using the autos data exported as a CSV):
However, while I get the same regression output as R when I apply weights, the output of hettest changes relative to the R code.
Produces: 1.06
Produces: 1.342911
What I would like to know is what hettest is doing following a weighted regression to help understand how to correct my formulas. Thank you for your time.
Code:
sysuse auto reg price mpg foreign hettest
Code:
autos <- read.csv("~/Downloads/autos.csv") mod <- lm(price~mpg+foreign, data=autos) resi <- mod$residuals sigma2 <- sum(resi^2)/nobs(mod) bpregSTATA <- lm(resi^2/sigma2~fitted(mod)) 0.5 * sum((bpregSTATA$fitted.values-mean(resi^2/sigma2))^2)
Code:
sysuse auto reg price mpg foreign [aweight=weight] hettest
Code:
modwt <- lm(price~ mpg + foreign, weights = weight, data=autos) resiwt <- modwt$residuals sigma2wt <- sum(resiwt^2)/nobs(modwt) bpregSTATAwt <- lm(resiwt^2/sigma2wt ~ fitted(modwt)) 0.5 * sum((bpregSTATAwt$fitted.values - mean(resiwt^2/sigma2wt))^2)
What I would like to know is what hettest is doing following a weighted regression to help understand how to correct my formulas. Thank you for your time.
Comment