Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Panel with negative Hausman


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Panel with negative Hausman
Date   Wed, 20 Apr 2011 20:31:57 +0100

This is very difficult to read.

In your code you appear to start off using ; as a delimiter but then
stop doing that. You can't just use delimiters as you fancy in Stata.
You must flag a delimiter change using #delimit.

There is some confusion here about defining and referencing macros.
For example, the line

local `depvar' y1

is unlikely to do what you think it does.

Nick

On Wed, Apr 20, 2011 at 8:02 PM, sam sampton <[email protected]> wrote:
> Dear Stata Users,
> Dealing with negative Hausman in panel est. I'm trying to run a version of this
> test (retrieved from the archive) under STATA 11 but got error:
>
>
> ---------------------------------- BEGIN --- foreric.do --- CUT HERE -------
> local id myid local depvar lnuncs local varlist lngdp ecrise ecfall urban
> lnhouse femalepa male1544        /*     */ lndiscr lnfree lnpts latin ssa deathp
> rulelaw protest cathol  /*      */ muslim transiti lnethv oecd war year89 year92
> year95  xtreg `depvar' `varlist', re hausman, save xthaus  xtreg `depvar'
> `varlist', fe hausman, less  tokenize `varlist' local i 1 while "``i''" != "" {
>        qui by `id':  gen double mean`i' = sum(``i'') / _n      qui by `id':  replace
> mean`i' = mean`i'[_n]   qui by `id':  gen double diff`i' = ``i'' - mean`i'      local
> newlist `newlist' mean`i' diff`i'       local i = `i' + 1 }  xtreg `depvar'
> `newlist' , re  qui test mean1 = mean1 , notest         /* clear test */ local i 2
> while "``i''" != "" {   if `b'[1,colnumb(`b', "mean`i'")] != 0 &        /*      */
> `b'[1,colnumb(`b', "diff`i'")]  != 0 {          qui test mean`i' = diff`i' , accum
> notest  }       local i = `i' + 1 } test  ----------------------------------   END
> --- foreric.do --- CUT HERE -------
>
> Resulting in (with my own varlist)
>
>> /* Perform suest test rather than Husman test (negative CHI2!)   */
>> local id id;
>
> . local `depvar' y1;
>
> . local `varlist' x1 x2 x3 x4 x5;
>
>>
>> tokenize `varlist';
>
> . local i 1
>> while "``i''" != "" {
>>         qui by `id':  gen double mean`i' = sum(``i'') / _n
>>         qui by `id':  replace mean`i' = mean`i'[_N]
>>         qui by `id':  gen double diff`i' = ``i'' - mean`i'
>>         local newlist `newlist' mean`i' diff`i'
>>
>>         local i = `i' + 1
>> }
>> ;
>
> . xtreg `depvar' `newlist' ;
>
> Random-effects GLS regression                   Number of obs      =       477
> Group variable: id                              Number of groups   =         9
>
> R-sq:  within  = 0.6599                         Obs per group:  min =        53
>       between = 0.9421                                        avg =      53.0
>       overall = 0.8080                                        max =        53
>
> Random effects u_i ~ Gaussian                   Wald chi2(5)       =    884.81
> corr(u_i, X)       = 0 (assumed)                Prob > chi2        =    0.0000
>
> ------------------------------------------------------------------------------
> y1          |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
> -------------+----------------------------------------------------------------
>          x1 |   .7123138   .0892791     7.98   0.000       .53733    .8872977
>          x2 |   .0226081   .0054684     4.13   0.000     .0118903     .033326
>          x3 |  -.0399303   .0638208    -0.63   0.532    -.1650167    .0851561
>          x4 |  -.3278316   .0913511    -3.59   0.000    -.5068766   -.1487867
>          x5 |   .0297908    .0152927     1.95   0.051    -.0001824     .059764
>       _cons |     3.4797   .7820005     4.45   0.000     1.947008    5.012393
> -------------+----------------------------------------------------------------
>     sigma_u |  .13777146
>     sigma_e |  .16628839
>         rho |  .40703053   (fraction of variance due to u_i)
> ------------------------------------------------------------------------------
>
> . tempname b
>> matrix `b' = e(b)
>>
>> qui test mean1 = diff1 , notest         /* clear test */
>> local i 2
>> while "``i''" != "" {
>>         if `b'[1,colnumb(`b', "mean`i'")] != 0 &
>>            `b'[1,colnumb(`b', "diff`i'")]  != 0 {
>>                 qui test mean`i' = diff`i' , accum notest
>>         }
>>         local i = `i' + 1
>> }
>> ;
> _= invalid name
> r(198);
>
> end of do-file
>
> r(198);
>
> Thanks for your help understanding  what's going on,
> Sam
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index