
clear
//Example 1
use "/Users/kaew/Documents/EE325/DATA_STATA/Table11.1.dta"
bro

// BPG-test or LM test(manual)
reg y x
predict u_hat, residual
generate u_hat_sq = u_hat^2
regress u_hat_sq x

// r-squared = 0.3621 => LM-statistic =n*r-squared = 9*0.3621 = 3.2589
// chi-square(d.f. = 1) 5% significant level = ....
// LM-statistic > Chi-square. So, we cannot reject Ho 
// of heteroskedasticity.

// BPGtest or LM test (STATA command)
reg y x 
estat hettest 
** Since p-value (prob>chi2) is more than 0.05, we cannot reject Ho at 5%
** significant level. We can conclude that we do not have heteroskedasticity.


// White-test (STATA command)

reg y x 
whitetst
** Since p-value (prob>chi2) is more than 0.05, we cannot reject Ho at 5%
** significant level. We can conclude that we do not have heteroskedasticity.


clear

//Example 2
//BPG test manual or LM test (Manual)
use "/Users/kaew/Documents/EE325/DATA_STATA/Table 11.5.dta"
reg rd sales
predict u_hat, residual
generate u_hat_sq = u_hat^2
regress u_hat_sq sales

// r-squared = 0.4309 => LM-statistic =n*r-squared = 14*0.4309 = 6.0326
// chi-square(d.f. = 1) 5% significant level = ......
// LM-statistic > Chi-square. So, we reject Ho in favor 
// of heteroskedasticity.

** Since we have heteroskedascity, we need to use the ,robust option.
reg rd sales, robust

// BPGtest or LM test (STATA command)
regress rd sales
estat hettest 
** Since p-value (prob>chi2) is less than 0.05, we reject Ho at 5%
** significant level. We can conclude that we have heteroskedasticity.
** Since we have heteroskedascity, we need to use the ,robust option.
reg rd sales, robust


//White-test (Manual)
reg rd sales
predict u_hat2, residual
generate u_hat2_sq = u_hat^2
gen salessq=sales^2
regress u_hat2_sq sales salessq
// r-squared = 0.4346 => LM-statistic =n*r-squared = 14*0.4309 = 6.090
// chi-square(d.f. = 1) 5% significant level = ......
// LM-statistic > Chi-square. So, we reject Ho in favor 
// of heteroskedasticity.


// White-test (STATA command)
reg rd sales
whitetst
** Since p-value (prob>chi2) is more than 0.05, we cannot reject Ho at 5%
** significant level. We can conclude that we do not have heteroskedasticity.
