How do I fix the unrecognized object error in Stargazer with a dynlm model?

假如想象 提交于 2021-02-20 19:01:47

问题


I calculated a dynlm model and now want to get stargazer to export that. However, stargazer does not return any output, instead gives me the Unrecognized object type Error. I already checkd if dynlm objects were supported by stargazer and according to the package page it is. Anyone have any idea what I'm getting wrong here? I know how to export the output with stargazer, but in this case it doesn't even show me the results inside of R. This is the model I used and the stargazer command, which returned the error. Really need your help! Thanks in Advance for any suggestions :)

model1 <- dynlm::dynlm(zz$AverageCONS~zz$GDPGrowth + zz$BRGOVMEHR, zz)
 summary(model1)

Time series regression with "zoo" data:
Start = 1981 Q1, End = 2005 Q1

Call:
dynlm::dynlm(formula = zz$AverageCONS ~ zz$GDPGrowth + zz$BRGOVMEHR, 
    data = zz)

Residuals:
    Min      1Q  Median      3Q     Max 
-13.827  -8.949  -5.658   3.577  63.916 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)    9.9902     1.9383   5.154 1.41e-06 ***
zz$GDPGrowth  -2.6026     2.1984  -1.184    0.239    
zz$BRGOVMEHR  -0.9483     3.5275  -0.269    0.789    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 14.46 on 94 degrees of freedom
Multiple R-squared:  0.02577,   Adjusted R-squared:  0.005042 
F-statistic: 1.243 on 2 and 94 DF,  p-value: 0.2931

> stargazer::stargazer(model1)

% Error: Unrecognized object type.

This is the dput for the regression!

> dput(zz)
structure(c(1.2, -0.2, -0.15, -0.1, 0.4, 0.333333333333333, 0.266666666666667, 
0.2, 0.5, 0.8, 1.1, 1.4, 1.3, 2, 2.7, 0.8, 0.9, 1, 0.8, 0.6, 
-0.6, -0.0666666666666667, 0.466666666666667, 1, 1.6, 2.2, 1.9, 
1.6, 1.7, 1.8, 1.5, 1.2, 0.8, 0.4, 0.8, 1.2, 2.1, 0.5, 1.15, 
1.8, 0.65, -0.5, 0.4, 1.3, 0.3, -0.7, -0.5, -0.3, -0.15, 0, 0.6, 
-0.1, 1.4, 0.3, 0.7, 0.2, -0.3, 0.8, 0.2, 0, -0.8, 1.4, 1.05, 
0.7, -0.5, 1.3, 1, 0.7, 0.15, -0.4, -0.4, -0.4, 1.2, 0, 0.4, 
0.8, 1.4, 0.8, 0, -0.3, 2, 0, -0.2, -0.2, -0.5, 0, 0.5, -0.2, 
-1.5, -0.35, 0.8, 0.3, -0.2, 0.5, 0.2, -0.1, 0, 0, 1.17870603993396, 
0.589353019966981, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.61936244127144, 
2.01801455396906, 0.416666666666667, 0, 2.16353957620116, 4.32707915240231, 
5.98174400514746, 7.6364088578926, 0.257076257076257, 0.171384171384171, 
0.0856920856920857, 0, 11.2103879729705, 22.4207759459411, 15.2347455885415, 
8.04871523114194, 11.3521305960255, 14.6555459609091, 15.4403121270985, 
16.2250782932878, 8.6979606817534, 1.17084307021898, 3.97895588789713, 
6.78706870557528, 0, 0, 4.87695592673415, 9.7539118534683, 4.87695592673415, 
0, 0, 0, 0, 0, 0.0201047586252623, 0.0402095172505245, 0.0201047586252623, 
0, 0, 0.0636265006342972, 0, 0.171974252305606, 0, 5.57623701563216, 
11.1524740312643, 2.68040672020172, 6.2111801242236, 3.24760735460988, 
28.2976799963101, 0, 3.7866135488981, 7.5732270977962, 0, 0, 
0.747061391598759, 1.49412278319752, 35.8503062293569, 70.2064896755162, 
52.105350122636, 34.0042105697558, 18.5823772614653, 18.0896275972026, 
13.25206168539, 8.41449577357745, 10, 0, 0, 34.7491138493683, 
8.36236933797909, 39.6563615833003, 74.4262295081967, 22.3611248302746, 
10, 16.455880420063, 22.911760840126, 0, 0.0666722800439236, 
0.0333361400219618, 0, 50.3843726943174, 0, 0, 0.864549845643277, 
1.72909969128655, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7.88127469343306, 
7.67671239967451, 7.50492078119126, 7.33312916270801, 7.26681550104175, 
7.37045715962304, 7.47409881820433, 7.57774047678561, 7.54440688341081, 
7.511073290036, 7.47773969666119, 7.44440610328638, 7.51950710910292, 
7.47703037780537, 7.43455364650782, 7.21735906430465, 7.07654252150171, 
6.93572597869877, 7.13426907080346, 7.33281216290814, 7.34110311728404, 
7.50058012443653, 7.66005713158903, 7.81953413874152, 7.80295976635758, 
7.78638539397364, 7.67221491798127, 7.5580444419889, 7.13119115282123, 
6.70433786365357, 6.73565901224693, 6.76698016084029, 6.8801068632748, 
6.9932335657093, 7.44235686960608, 7.89148017350285, 8.24705859843768, 
8.20161269191644, 7.1659119101912, 6.13021112846596, 6.7880423795211, 
7.44587363057623, 7.46757903053749, 7.48928443049876, 7.07702561011456, 
6.66476678973035, 6.57551271762131, 6.48625864551226, 6.31270117005075, 
6.13914369458924, 6.05634679973895, 5.9702909369734, 6.19216550005443, 
6.87967122943963, 7.49940214266322, 7.29465702788788, 7.08991191311255, 
7.3351806925688, 7.46762039999888, 7.22336518577119, 6.75192112299076, 
6.61614229895973, 6.50505157543993, 6.39396085192013, 6.09682321355397, 
5.99711627005931, 5.97786567725074, 5.95861508444216, 6.13656719089965, 
6.31451929735713, 6.19389219496854, 6.07326509257996, 7.58677238161551, 
7.24041796080827, 6.96794618067372, 6.69547440053917, 7.72437292977251, 
7.61985191697131, 7.85861327446016, 7.78974162557168, 8.00182694049075, 
7.82019060836613, 7.58946475073855, 7.89751118735182, 7.14978411180804, 
7.30379876152907, 7.4578134112501, 6.24455242517448, 5.8823776113788, 
5.98170501192132, 6.08103241246385, 5.73879250743035, 5.68128370028589, 
5.83312282222293, 6.1665241256249, 6.49992542902688, 6.45920800878159
), .Dim = c(97L, 4L), .Dimnames = list(NULL, c("GDPGrowth", "AverageCONS", 
"BRGOVMEHR", "ApprovalGOV")), index = structure(c(1981, 1981.25, 
1981.5, 1981.75, 1982, 1982.25, 1982.5, 1982.75, 1983, 1983.25, 
1983.5, 1983.75, 1984, 1984.25, 1984.5, 1984.75, 1985, 1985.25, 
1985.5, 1985.75, 1986, 1986.25, 1986.5, 1986.75, 1987, 1987.25, 
1987.5, 1987.75, 1988, 1988.25, 1988.5, 1988.75, 1989, 1989.25, 
1989.5, 1989.75, 1990, 1990.25, 1990.5, 1990.75, 1991, 1991.25, 
1991.5, 1991.75, 1992, 1992.25, 1992.5, 1992.75, 1993, 1993.25, 
1993.5, 1993.75, 1994, 1994.25, 1994.5, 1994.75, 1995, 1995.25, 
1995.5, 1995.75, 1996, 1996.25, 1996.5, 1996.75, 1997, 1997.25, 
1997.5, 1997.75, 1998, 1998.25, 1998.5, 1998.75, 1999, 1999.25, 
1999.5, 1999.75, 2000, 2000.25, 2000.5, 2000.75, 2001, 2001.25, 
2001.5, 2001.75, 2002, 2002.25, 2002.5, 2002.75, 2003, 2003.25, 
2003.5, 2003.75, 2004, 2004.25, 2004.5, 2004.75, 2005), class = "yearqtr"), class = "zoo")
> 

回答1:


There are several problems:

  1. By writing dynlm::dynlm the dynlm package is only known at that point but not by stargazer.
  2. zz should not be used in the formula.

Write it like this:

library(dynlm)
library(stargazer)

model1 <- dynlm(AverageCONS ~ GDPGrowth + BRGOVMEHR, zz)
stargazer(model1)

giving:

% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Mon, Dec 30, 2019 - 12:13:12 PM
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & AverageCONS \\ 
\hline \\[-1.8ex] 
 GDPGrowth & $-$2.603 \\ 
  & (2.198) \\ 
  & \\ 
 BRGOVMEHR & $-$0.948 \\ 
  & (3.527) \\ 
  & \\ 
 Constant & 9.990$^{***}$ \\ 
  & (1.938) \\ 
  & \\ 
\hline \\[-1.8ex] 
Observations & 97 \\ 
R$^{2}$ & 0.026 \\ 
Adjusted R$^{2}$ & 0.005 \\ 
Residual Std. Error & 14.456 (df = 94) \\ 
F Statistic & 1.243 (df = 2; 94) \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 


来源:https://stackoverflow.com/questions/59528346/how-do-i-fix-the-unrecognized-object-error-in-stargazer-with-a-dynlm-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!