[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
vwiggins@stata.com (Vince Wiggins, StataCorp) |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: hausman and xthausman after panel fe, re - DROPPED MEAN/DIFF |

Date |
Thu, 25 Aug 2005 17:34:47 -0500 |

Joana Quina <joana.quina@gmail.com> notes that the snippet of code that was included in my earlier post about the Hausman test will not work if any of the covariates are constant within panels, > I used your code for the augmented Hausman test, but whenever I > include time-invariant variables (or time dummies interacted with > time-invariant variables), it does note work - Stata drops the mean > for the time-invariant variable (or the diff for the interacted > terms). [...] Such variables are dropped from the fixed effects (FE) regression because they are collinear with the effects and the code was not up to that. Eric's models from some 3 years ago did not have this problem, but Joana's models do, and such variables are quite common. To make the code resistant to such variables, we just have to make sure that they are not tested. We could do that by wrapping the tests in an additional -if- that checks for the existence of differenced and mean variables in the estimation results, if colnumb(`b', "mean`i'") < . & colnumb(`b', "diff`i'") < . { ... } The final section of code then becomes, ------------------------------------ BEGIN code snippet ------------------- quietly test mean1 = diff1 , notest /* clear test */ local i 2 while "``i''" != "" { if colnumb(`b', "mean`i'") < . & colnumb(`b', "diff`i'") < . { if `b'[1,colnumb(`b', "mean`i'")] != 0 & /* */ `b'[1,colnumb(`b', "diff`i'")] != 0 { quietly test mean`i' = diff`i' , accum notest } } local i = `i' + 1 } test ------------------------------------ END code snippet ------------------- Note that because we initialize the testing loop with -quietly test mean1 = diff1 , notest- the first variable in our <varlist> cannot be constant within panel. Having said that, I like the version of the artificial (augmented) regression that Mark Schaffer <M.E.Schaffer@hw.ac.uk> and Carl Nelson <chnelson@uiuc.edu> use better that my own. Adapting theirs to loop over a <varlist> we get, ---------------------------------- BEGIN --- artreg0.do --- CUT HERE ------- local id idcode local depvar ln_wage local varlist ttl_exp union white iis `id' local i 0 foreach var of varlist `varlist' { egen mymean`++i' = mean(`var'), by(`id') } xtreg `depvar' `varlist' mymean1-mymean`i' , re testparm mymean1-mymean`i' ---------------------------------- END --- artreg0.do --- CUT HERE ------- It is much shorter and will work with variables that are constant within panels. Again, replace -idcode-, -ln_wage-, and -ttl_exp union white- with your own id variable, dependent variable, and independent variables. Also note, that both of these snippets assume that you do not have any missing values in you covariates, dependent variable, or id variable. If Joana has missing data, she should take care to compute the means only over the estimation sample. A better version, and one that does this is, ---------------------------------- BEGIN --- artreg.do --- CUT HERE ------- local id idcode local depvar ln_wage local varlist ttl_exp union white iis `id' xtreg `depvar' `varlist' , re local i 0 foreach var of varlist `varlist' { egen mymean`++i' = mean(`var'), by(`id') } xtreg `depvar' `varlist' mymean1-mymean`i' , re testparm mymean1-mymean`i' ---------------------------------- END --- artreg.do --- CUT HERE ------- This is a different form of artificial regression than the one from my first post and will differ slightly with small samples, but they are asymptotically equivalent. -- Vince vwiggins@stata.com * * 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/

- Prev by Date:
**Re: st: RE: Create Dataset from Nowhere in Stata** - Next by Date:
**Re: st: hausman and xthausman after panel fe, re** - Previous by thread:
**st: RE: Create Dataset from Nowhere in Stata** - Next by thread:
**Re: st: hausman and xthausman after panel fe, re - DROPPED MEAN/DIFF** - Index(es):

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