After doing a linear regression, I would like the result to print in a table with the stargazer library with type="html", but the console prints a set of html codes instead of the table. This is some of what I did:
cpbi_ts= ts(cpbi,
start = 1988,
end = 2018 )
tc_ts=ts(VITRM,
start = 1988,
end = 2018 )
data_1= ts.union(cpbi_ts,tc_ts)
m1=lm(cpbi_ts~tc_ts,
start = 1998,
end = 2018)
stargazer(m1,type="html",align = FALSE, no.space=FALSE)
when the last line of code is executed, the result should be a table but the console prints:
<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>cpbi_ts</td></tr>
<tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">tc_ts</td><td>-0.094<sup>**</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.035)</td></tr>
<tr><td style="text-align:left"></td><td></td></tr>
<tr><td style="text-align:left">Constant</td><td>0.024<sup>**</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.011)</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>21</td></tr>
<tr><td style="text-align:left">R<sup>2</sup></td><td>0.280</td></tr>
<tr><td style="text-align:left">Adjusted R<sup>2</sup></td><td>0.240</td></tr>
<tr><td style="text-align:left">Residual Std. Error</td><td>0.051 (df = 19)</td></tr>
<tr><td style="text-align:left">F Statistic</td><td>7.400<sup>**</sup> (df = 1; 19)</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>
It seems you need to add the argument
out
to the functionstargazer
Then you can open the file from your working directory and you will be able to see the table, in my case this is what I get:
stargazer
is a package intended to integrate withRmarkdown
, that is, write R code with Markdown code, for example, something like this in a document frameRmd
:Pressing the button
knitr
would output something like this:This can be viewed directly in Rstudio 's "Viewer" panel or in a separate window (as well as being exportable to Word or PDF). Note: In order to reproduce the example, the code would have to be pasted into a new RMarkdown document.
Now, if what you are looking for is to use
stargazer()
within a common R script, the only thing you will see is the code necessary to "draw" the table (eventually, text, html or latex). You can, yes, use the output optiontype="text"
, to output something like this:The console output would be something like this:
Another way, for which you already have an answer, would be to save the output as a
html
complete and view it with the browser. Otherwise, there is a practical way to automate this. Here the answer , the only thing I did was to modify the name of the function:So you can do: