Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Problems with -hetgrot-


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: Problems with -hetgrot-
Date   Sun, 14 Mar 2004 16:13:54 -0600

----- Original Message ----- 
From: "Clive Nicholas" <[email protected]>
To: <[email protected]>
Sent: Saturday, March 13, 2004 6:43 PM
Subject: st: Problems with -hetgrot-


> All,
>
> After plenty of 'behind-the-curtains' discussions with Richard Williams,
> we agreed that it would be a good idea to bring this to the attention of
> the list.
>
> Essentially, there appear to be problems in getting sensible chi-squared
> estimates out of -hetgrot-, a user-written procedure testing for groupwise
> heteroscedascity after -reg-, -areg-, -xtreg- and -xtgls- (I've been
> calling it after the last of these) which is based on a proposal by Greene
> (1993: 395).
>

Clive,

No doubt there are more efficient ways to do this, but here is an implementation
that seems to work.

Scott


*! version 1.0.0   March 14, 2004 Scott Merryman
* See Greene "Econometric Analysis" 4th ed page 511
* Adapted from -hetgrot- by Luca Nunziata  (Version 1.0, 1/4/00)
* and from -gwhet- by  Gregorio Impavido  (Version 1.1.0 09/10/98)
* syntax for xtgls, xtreg, and areg: gwhet2
* syntax for reg: gwhet2, group(varname)

program gwhet2, rclass
 version 8.2
 syntax, [group(varname)]
 tempvar touse
 qui gen byte `touse' = e(sample)
 preserve
 qui drop if `touse'==0

 tempvar  N_total N_g simga yhat e e2 sigma_n
 tempname LR sigma sigma_n pval sum_sigma_n df


 if e(cmd) == "regress" {
  local id `group'
  qui tab `id'
  scalar `N_g' = r(r)
  qui predict double `e' if `touse', res
 }

 if  e(cmd)== "areg" {
  local id "`e(absvar)'"
  scalar `N_g' = `e(df_a)' +1
  qui predict double `e' if `touse', res
 }

 if e(cmd)=="xtreg" {
  local id "`e(ivar)'"
  scalar `N_g' = `e(N_g)'
  qui predict double `e' if `touse', e
 }

 if e(cmd)=="xtgls" {
  local id "`e(ivar)'"
  scalar `N_g' = `e(N_g)'
  qui predict double `yhat' if `touse', xb
  qui gen double `e' = `e(depvar)' - `yhat'
 }

 if e(cmd)~="regress" & e(cmd)~="areg" & e(cmd)~="xtreg" & e(cmd)~="xtgls"{
 display in red "gwhet only works with regress, xtreg, xtgls or areg"
 exit 301
 }

 qui gen double `e2' = `e'^2 if `touse'
 sum `e2' , meanonly
 scalar `N_total' = r(N)
 scalar `sigma' = r(sum)/r(N)

 qui gen double `sigma_n' = .
 scalar `sum_sigma_n' = 0

 qui levels `id' , local(levels)
 foreach l of local levels {
  qui {
   sum `e2' if `id' == `l' , meanonly
   replace  `sigma_n' = ln(r(sum)/r(N))*r(N)  if `id' == `l'
   sum `sigma_n'   if `id' == `l', meanonly
   scalar `sum_sigma_n' = `sum_sigma_n' + r(mean)
   }
 }



 scalar `LR'=`N_total'*ln(`sigma')- `sum_sigma_n'
 scalar `df' = `N_g' - 1
 scalar `pval'= chiprob(`df',`LR')


 display""
 display in green "Testing for Groupwise heteroscedasticity"
 display""
 display "Ho: homoscedasticity"
 display "H1: groupwise heteroscedasticity by " "`id'"
 disp in gr "chi2 (" `df' ")  =" in ye _col(16) %8.2f `LR'
 disp in gr "Prob>chi2 = " in ye _col(16) %8.4f `pval'
 display""


 return scalar df = `df'
 return scalar LR = `LR'
 return scalar pval= `pval'
 return local test_name  "gwhet2"
 restore


end

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index