我正在尝试使用我最喜欢的软件包之一 stargazer 创建一个包含 7 个回归模型的 LaTeX 表。这曾经工作得很好,但自从最近更新后(我最近更新,不确定原始更新何时完成),当我尝试使用五个以上模型时,我收到以下错误:
Error in if (is.na(s)) { : the condition has length > 1
没有 NA 观测,当我在观星仪中单独使用这些模型时,它们都可以工作。事实上,任何模型组合都可以工作,直到我尝试同时使用五个模型。
我相信这个问题已经被问过here,但不幸的是原始问题没有包含可重现的示例。
这是我的例子。该数据是 SCF 的片段,公共数据也是如此。 请注意,即使您不使用加权 OLS,问题仍然存在。
c = structure(list(EQTY_share = c(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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0), MARRIED_pre = c(1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0,
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1,
1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1), HHSEX_pre = c(1,
0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1,
0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1), WGT = structure(c(4930.39000347177,
4704.28320650246, 3917.62527383248, 4679.17065856539, 4532.8338744778,
5464.86420532948, 4009.96585980657, 3520.96256713686, 4669.00210194531,
3794.02574047393, 3587.72518977287, 7367.07278373586, 4588.01315976255,
4951.76614322902, 5771.82430259193, 3034.97178165389, 6667.74113876358,
5114.41871363052, 4423.91513876153, 4280.69801738373, 4397.70185006764,
4202.32384820713, 3916.03065036868, 4904.89146933682, 4058.00537449477,
3338.502849759, 3051.27717471459, 4343.63230511208, 5742.1802439261,
4649.67239557703, 3631.54523664957, 4811.86440418757, 5369.22303775956,
4441.90412465946, 3557.07767919729, 4890.94114408006, 4533.54312102598,
3984.2155629655, 5340.07854470022, 4970.64563797337, 4787.25645412662,
3255.88142416359, 3229.53685529925, 5428.68152102248, 4524.95540626004,
3689.00506972271, 5845.04667795468, 3952.03167801739, 4510.48081497025,
3012.97658112975, 5503.562879449, 5122.85294981916, 4374.01742982708,
5025.86608234395, 5097.92377468931, 3519.89950503538, 5229.9081990759,
7958.45615305438, 4410.38758473807, 4037.32598628441, 4059.69894370641,
8367.02126269777, 3747.46507881708, 4001.90172707809, 4336.66654844803,
4962.69416520992, 3335.07507341588, 3497.60482318488, 4875.86681908647,
6741.09375061725, 6723.7169945403, 2550.48863056955, 4960.45588060922,
4301.85352631122, 4912.52010780385), label = "X42001: CONSISTENT WGT: REVISED KW", format.stata = "%12.0g")), row.names = c(NA,
-75L), class = c("tbl_df", "tbl", "data.frame"))
share_eqty <- lm(data = c,
weights = WGT,
formula = EQTY_share ~ MARRIED_pre + HHSEX_pre
)
#The following generates a LaTeX table
stargazer(share_eqty,share_eqty,share_eqty,share_eqty,share_eqty)
#The following generates the error "Error in if (is.na(s)) { : the condition has length > 1"
stargazer(share_eqty,share_eqty,share_eqty,share_eqty,share_eqty,share_eqty)
任何帮助将不胜感激。
这尝试检查 NA,单独检查每个模型,并使用模型的不同组合。我认为这些都不是问题,因为当使用同一模型超过 5 次时也会出现这种情况。 我还尝试生成随机数据并对其进行回归,在这种情况下,问题不会出现。 (Stargazer 在 5 个以上的型号中按预期工作。)
share_eqty
更改为
s1
并且它有效。我建议向 stargazer 软件包维护者提交错误报告