Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic heterogeneous panel using the xtprmg command - Hausman test

    Hi everyone,

    I have a panel dataset of countries and years. I am undertaking a dynamic heterogeneous panel using the xtprmg command (pooled mean group pmg, mean group mg and dynamic fixed effects dfe). I have a list of explanatory variables of interest and I would like to run the command below:

    local ivar1 interest1
    local ivar2 interest2
    local ivar3 interest3
    local ivar4 interest4
    ...
    local ivarn interest

    forv i=1/n {

    xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' )
    estimates store pmg
    drop __ec
    xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' ) mg
    estimates store mg
    hausman mg pmg, sigmamore
    xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' ) dfe
    estimates store dfe
    hausman mg dfe, sigmamore
    outreg2 [pmg mg dfe] using "$temp_dir\results.xls"
    }

    I would be grateful if you could advise on how to report the p-values of the two Hausman tests in the outreg2.

    Many thanks in advance.

    Jala

  • #2
    Code:
    webuse nlswork4, clear
    xtreg ln_wage age msp ttl_exp, fe
    estimates store fixed
    xtreg ln_wage age msp ttl_exp, re
    estimates store random
    hausman fixed random, sigmamore
    local hausman= cond(`r(p)'<0.01, string(`r(chi2)', "%9.3f") + "***", ///
                       cond(`r(p)'<0.05, string(`r(chi2)', "%9.3f")+"**", ///
                           cond(`r(p)'<0.1, string(`r(chi2)', "%9.3f")+"*", ///
                               string(`r(chi2)', "%9.3f"))))
    outreg2 [fixed] using myfile, replace addtext(Hausman stat., "`hausman'")
    outreg2 [random] using myfile, append
    Res.:
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	23.0 KB
ID:	1707482

    Comment


    • #3
      Thanks a lot Andrew Musau for your prompt and useful response.

      Sorry to bother you again, I have another clarification question: I prefer to report the p-value of the test rather than its statistic. Could you please advise on the relevant code?

      Many thanks once again.

      Jala

      Comment


      • #4
        Code:
        webuse nlswork4, clear
        xtreg ln_wage age msp ttl_exp, fe
        estimates store fixed
        xtreg ln_wage age msp ttl_exp, re
        estimates store random
        hausman fixed random, sigmamore
        local hausman= cond(`r(p)'<0.01, "p<0.01", "p=" + string(`r(p)', "%4.3f"))
        outreg2 [fixed] using myfile, replace addtext(Hausman test, "`hausman'")
        outreg2 [random] using myfile, append
        Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	22.7 KB
ID:	1707548

        Last edited by Andrew Musau; 28 Mar 2023, 16:06.

        Comment


        • #5
          Thanks a lot Andrew Musau . This is super helpful and it works perfectly.

          On a separate yet related note, I have a problem with the code I mentioned earlier (please find it below after updating it with the p value of Hausman test). The output file "results.xls" would only show the results with the last ivarn and disregards the results for the rest of the variables of interest (ivar1, ivar2, etc.). I would be grateful if you could advise on how to fix this.

          local ivar1 interest1
          local ivar2 interest2
          local ivar3 interest3
          local ivar4 interest4
          ...
          local ivarn interest

          forv i=1/n {

          xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' )
          estimates store pmg
          drop __ec
          xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' ) mg
          estimates store mg
          hausman mg pmg, sigmamore
          local hausman= r(p)
          xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' ) dfe
          estimates store dfe
          outreg2 [pmg mg dfe] using "$temp_dir\results.xls", replace addtext(Hausman test, "`hausman'")
          }

          Comment


          • #6
            You are overwriting the estimates while looping. You need:

            Code:
            forval i=1/n {
                xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' )
                estimates store pmg`i'
                drop __ec
                xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' ) mg
                estimates store mg`i'
                hausman mg`i' pmg`i', sigmamore
                local hausman= r(p)
                xtpmg d(y x1 x2 `ivar`i'' ), lr(l.y x1 x2 `ivar`i'' ) dfe
                estimates store dfe`i'
                outreg2 [pmg1 mg1 dfe1 pmg2 mg2 dfe2 ...] using "$temp_dir\results.xls", replace addtext(Hausman test, "`hausman'")
            }

            Comment


            • #7
              Thanks a lot Andrew Musau. I really appreciate all your help.

              Just a clarification question, in this case just to make sure the "local hausman" would pick the p-value for each ivar regression, do you think I also need to add an 'i' next to it like this:
              local hausman`i'= r(p) ? if this is the case, should I also reflect in the replace add text in the outreg?

              Thank you again so much and apologies for the too many questions.

              Jala

              Comment


              • #8
                Yes, such that you have:

                Code:
                outreg2 [pmg1] using myfile, replace addtext(Hausman test, "`hausman1'")
                outreg2 [mg1 dfe1] using myfile, append
                
                outreg2 [pmg2] using myfile, append addtext(Hausman test, "`hausman2'")
                outreg2 [mg2 dfe2] using myfile, append
                and so on.

                Comment

                Working...
                X