'Hausman test in WORD in R
I want to transform the Hausman tests results into html so I can use them in my paper.
The following code is not working.
Do you have any ideas why?
Hausman <- phtest(MOD.FE.TIME, MOD.RANDOM)
stargazer(Hausman, title = "Hausman Test", style = "default", decimal.mark = ",",
out = "Hausmann.html")
The error given by R is:
% Error: Unrecognized object type.
Solution 1:[1]
I think it is simply that phtest models are not supported by stargazer.
According to stargazer_models the models supported from the plm package are pgmm, plm and pmg.
Solution 2:[2]
library(plm)
data("Gasoline", package = "plm")
form <- lgaspcar ~ lincomep + lrpmg + lcarpcap
wi <- plm(form, data = Gasoline, model = "within")
re <- plm(form, data = Gasoline, model = "random")
phtest(wi, re) -> my_ph_test
Stargazer can print any data frame into html or latex if you just set summary=FALSE. You can transform the phtest object into a data frame by broom::tidy().
library(broom)
tidy(my_ph_test) -> my_ph_test
Unfortunately, phtest object has some incompatibilities with tidy, so you need to manually transform the numeric vectors into numbers
my_ph_test$statistic <- round(as.numeric(my_ph_test$statistic),3)
my_ph_test$p.value <- round(as.numeric(my_ph_test$p.value),3)
my_ph_test$parameter <- as.numeric(my_ph_test$parameter)
You might also want to rename your columns to make them more descriptive:
names(my_ph_test)[1:3] <- c('Chisq', 'P-value','df')
Finally, generate the table library(stargazer) stargazer(my_ph_test, summary=FALSE, type='html')
Output:
<table style="text-align:center"><tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td>Chisq</td><td>P-value</td><td>df</td><td>method</td><td>alternative</td></tr>
<tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">1</td><td>302.804</td><td>0</td><td>3</td><td>Hausman Test</td><td>one model is inconsistent</td></tr>
<tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr></table>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | neilfws |
| Solution 2 | Otto Kässi |
