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

st: Deleteing cases without warning in -hetgrot-


From   "Clive Nicholas" <Clive.Nicholas@newcastle.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: Deleteing cases without warning in -hetgrot-
Date   Mon, 8 Mar 2004 13:31:47 -0000 (GMT)

All,

This is another problem I've been working with Brian on, but unfortunately
to no avail (although this is certainly _not_ Brian's fault!). Below is
the original question (with revisions) to Stata's technical support, which
Brian answered last Wednesday.

After running models in -xtgls-, I've been using an extremely useful test
devised by Luca Nunziata called -hetgrot-, which tests for panel-level
heteroscedasticity. I was helpfully pointed to this routine by another
member of Statalist.

Unfortunately, there's a problem. After calling -hetgrot [panelvar]- (which
runs the test), the ado-file deletes one or two observations from each
panel in the dataset. As you can imagine, this is quite disconcerting, and
it means that I have to -exit, clear- each time.

I'm sure there's something in the code that causes this (and perhaps
correctly, because of the degrees of freedom consumed in calculating the
statistic). Can anybody see any way around this?

----------------------------------------------------------------------------
prog def hetgrot, rclass

***by Luca Nunziata, Nuffield College, Oxford
***Version 1.0, 1/4/00
version 6

tempvar nind nindg e xbgls temp1 temp2 sig sigg a sumg arg
tempname sig sumg LR

if "`1'"=="" {
	display in red "ERROR, Name of group variable required as 1st argument"
	exit
}

if e(cmd)=="" {
	display in red "ERROR, need reg, xtreg or areg as command"
	exit 498
}

if e(cmd)== "regress" | e(cmd)== "areg" {
	predict `e', res
}

if e(cmd)=="xtreg" {
	predict `e', e
}

if e(cmd)=="xtgls" {
	predict `xbgls'
	gen `e'=$S_E_depv-`xbgls'
}

if e(cmd)~="regress" & e(cmd)~="areg" & e(cmd)~="xtreg" & e(cmd)~="xtgls"{
	display in red "ERROR, need reg, xtreg, xtgls or areg as command"
	exit 301
}

qui {
gen `temp1'=1 if e(sample)==1

egen `nindg'= count(`temp1'), by (`1')

drop if e(sample)==0


*determination of number of groups
egen `nind' = group(`1')

replace `nind'=`nind'[_N]
scalar `nind'=`nind'[_N]


*calculation of sigma
replace `e'=`e'^2
gen `sig'=sum(`e')
replace `sig'=`sig'[_N]/`nind'

scalar `sig'=`sig'[_N]/`nind'

*calculation of sigman
egen `sigg'=sum(`e'), by (`1')
replace `sigg'=`sigg'/`nindg'


***calculation of LR test statistic
*sum of groups var
sort `1'
by `1': gen `a'=1 if _n==_N
replace `sigg'=log(`sigg')
qui gen `arg'=`sigg'*`a'*`nindg'
egen `sumg'=sum(`arg')
scalar `sumg'=`sumg'

scalar `LR'=`nind'*log(`sig')-`sumg'
return scalar lr= `LR'
return scalar pval= chiprob(`nind'-1,`LR')

}

*display results

display""
display in green "Testing for Groupwise heteroscedasticity"
display""
display "Ho: homoscedasticity"
display "H1: groupwise heteroscedasticity by " "`1'"
display""
di _col(10) in gr "chi2(" in ye `nind'-1 in gr ")" /*
	*/ _col(23) "=" in ye /*
	*/	_col(25) %9.2f `LR'
	di _col(10) in gr "Prob > chi2  =" in ye _col(30) /*
	*/	%6.4f chiprob(`nind'-1,`LR')

end
----------------------------------------------------------------------------

CLIVE NICHOLAS        |t: 0(44)191 222 5969
Politics Building     |e: clive.nicholas@ncl.ac.uk
School of Geography,  |f: 0(44)870 126 2421
 Politics & Sociology |
University of         |
 Newcastle-upon-Tyne  |
Newcastle-upon-Tyne   |
NE1 7RU		      |
United Kingdom	      |http://www.ncl.ac.uk/geps
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index