R: Stargazer outputs html code and does not generate a table

75 Views Asked by At

I have a problem with stargazer().

I want to regress y on log_GDP and show the result in atable by using stargazer(). The code below only outputs html code and does not generate a table. I also tried with "text" and LaTex, but none of them generated a table properly. How can I solve this issue? Thank you in advance.

lm_model_constant <- lm(y ~ 1 + log_GDP, data = data_selected)
install.packages("stargazer", repos = "http://cran.r-project.org")
library("stargazer")
stargazer(lm_model_constant, type = "html")

This is the output(html code).

<table style="text-align:center"><tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td><em>Dependent variable:</em></td></tr>
<tr><td></td><td colspan="1" style="border-bottom: 1px solid black"></td></tr>
<tr><td style="text-align:left"></td><td>y</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">log_GDP</td><td>20.759<sup>***</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.762)</td></tr>
<tr><td style="text-align:left"></td><td></td></tr>
<tr><td style="text-align:left">Constant</td><td>-141.137<sup>***</sup></td></tr>
<tr><td style="text-align:left"></td><td>(7.079)</td></tr>
<tr><td style="text-align:left"></td><td></td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Observations</td><td>184</td></tr>
<tr><td style="text-align:left">R<sup>2</sup></td><td>0.803</td></tr>
<tr><td style="text-align:left">Adjusted R<sup>2</sup></td><td>0.802</td></tr>
<tr><td style="text-align:left">Residual Std. Error</td><td>12.430 (df = 182)</td></tr>
<tr><td style="text-align:left">F Statistic</td><td>742.169<sup>***</sup> (df = 1; 182)</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"><em>Note:</em></td><td style="text-align:right"><sup>*</sup>p<0.1; <sup>**</sup>p<0.05; <sup>***</sup>p<0.01</td></tr>
</table>
1

There are 1 best solutions below

0
On

I don't have your data but here is a way to get a summary table in html with gtsummary.

library(gtsummary)


lm_model_constant <- lm(cyl~ 1 + vs, data = mtcars)  

tbl_regression(lm_model_constant, intercept = TRUE)