我正在尝试使用R中的Stargazer包创建一个回归表。我有几个回归,仅在虚拟变量中有所不同。我希望它报告自变量的系数,常数等,并且如果在回归中包括某些固定效应(即虚拟变量),则说“是”或“否”。这些是我的回归:
iv1 <- ivreg(data=merge1,log(total_units)~log(priceIndex)|log(taxIndex))
iv2 <- ivreg(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)|log(taxIndex)+factor(fips_state_code))
iv4 <- ivreg(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code) +factor(year)|log(taxIndex)+factor(fips_state_code) +factor(year))
iv5 <- ivreg(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code) +time*factor(fips_state_code)|log(taxIndex)+factor(fips_state_code) +time*factor(fips_state_code))
(顺便提一下,数据框代码在底部。)
如你所见,iv1没有假人。 iv2有状态假人。 iv4有州和年假人。 iv5有状态假人和时间趋势假人。
我不想报告所有这些假人的测试版,而是希望回归能够简单地报告是否包含了每个假人。出于某种原因,我可以使用Stargazer为每个单独的回归工作,因为:
> stargazer(iv1,type="text",
+ omit = c("fips_state_code","year","time"),
+ omit.labels = c("State FE?","Year FE?","State time trend?"))
===============================================
Dependent variable:
---------------------------
log(total_units)
-----------------------------------------------
log(priceIndex) 1.146
(1.481)
Constant -0.283
(3.576)
-----------------------------------------------
State FE? No
Year FE? No
State time trend? No
-----------------------------------------------
Observations 189
R2 -1.347
Adjusted R2 -1.359
Residual Std. Error 1.297 (df = 187)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
>
> stargazer(iv2,type="text",
+ omit = c("fips_state_code","year","time"),
+ omit.labels = c("State FE?","Year FE?","State time trend?"))
===============================================
Dependent variable:
---------------------------
log(total_units)
-----------------------------------------------
log(priceIndex) 1.184
(1.561)
Constant -0.495
(3.767)
-----------------------------------------------
State FE? Yes
Year FE? No
State time trend? No
-----------------------------------------------
Observations 189
R2 -1.130
Adjusted R2 -1.487
Residual Std. Error 1.332 (df = 161)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
>
> stargazer(iv4,type="text",
+ omit = c("fips_state_code","year","time"),
+ omit.labels = c("State FE?","Year FE?","State time trend?"))
===============================================
Dependent variable:
---------------------------
log(total_units)
-----------------------------------------------
log(priceIndex) 0.845
(1.049)
Constant 0.342
(2.619)
-----------------------------------------------
State FE? Yes
Year FE? Yes
State time trend? No
-----------------------------------------------
Observations 189
R2 -0.393
Adjusted R2 -0.690
Residual Std. Error 1.098 (df = 155)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
>
> stargazer(iv5,type="text",
+ omit = c("fips_state_code","year","time"),
+ omit.labels = c("State FE?","Year FE?","State time trend?"))
===============================================
Dependent variable:
---------------------------
log(total_units)
-----------------------------------------------
log(priceIndex) 0.554
(1.064)
Constant 0.041
(2.393)
-----------------------------------------------
State FE? Yes
Year FE? No
State time trend? Yes
-----------------------------------------------
Observations 189
R2 -0.001
Adjusted R2 -0.405
Residual Std. Error 1.001 (df = 134)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
但是,当我尝试同时进行多次回归时,情况会变得奇怪:
> stargazer(iv1,iv2,iv4,iv5,type="text",
+ omit = c("fips_state_code","year","time"),
+ omit.labels = c("State FE?","Year FE?","State time trend?"))
=======================================================================================
Dependent variable:
-------------------------------------------------------------------
log(total_units)
(1) (2) (3) (4)
---------------------------------------------------------------------------------------
log(priceIndex) 1.146 1.184 0.845 0.554
(1.481) (1.561) (1.049) (1.064)
Constant -0.283 -0.495 0.342 0.041
(3.576) (3.767) (2.619) (2.393)
---------------------------------------------------------------------------------------
State FE? No No No No
Year FE? No No No No
State time trend? No No No No
---------------------------------------------------------------------------------------
Observations 189 189 189 189
R2 -1.347 -1.130 -0.393 -0.001
Adjusted R2 -1.359 -1.487 -0.690 -0.405
Residual Std. Error 1.297 (df = 187) 1.332 (df = 161) 1.098 (df = 155) 1.001 (df = 134)
=======================================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
注意现在所有的假人都被报告为“不”。似乎iv1的使用,没有傻瓜,抛出了Stargazer。我不确定为什么会这样!
所以,我的问题是:如何将组合的Stargazer输出看起来像这样?
=======================================================================================
Dependent variable:
-------------------------------------------------------------------
log(total_units)
(1) (2) (3) (4)
---------------------------------------------------------------------------------------
log(priceIndex) 1.146 1.184 0.845 0.554
(1.481) (1.561) (1.049) (1.064)
Constant -0.283 -0.495 0.342 0.041
(3.576) (3.767) (2.619) (2.393)
---------------------------------------------------------------------------------------
State FE? No Yes Yes Yes
Year FE? No No Yes No
State time trend? No No No Yes
---------------------------------------------------------------------------------------
Observations 189 189 189 189
R2 -1.347 -1.130 -0.393 -0.001
Adjusted R2 -1.359 -1.487 -0.690 -0.405
Residual Std. Error 1.297 (df = 187) 1.332 (df = 161) 1.098 (df = 155) 1.001 (df = 134)
=======================================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
我知道这似乎是一个愚蠢的问题。但我试图做更多的回归,每次手动格式化是一个巨大的痛苦。任何和所有建议都会有所帮助!感谢。
这是我的数据:
structure(list(year = c(2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L), fips_state_code = c(4, 5, 6, 8, 9, 10,
11, 12, 13, 17, 18, 21, 22, 24, 25, 27, 29, 31, 32, 34, 35, 36,
38, 45, 46, 48, 55, 4, 5, 6, 8, 9, 10, 11, 12, 13, 17, 18, 21,
22, 24, 25, 27, 29, 31, 32, 34, 35, 36, 38, 45, 46, 48, 55, 4,
5, 6, 8, 9, 10, 11, 12, 13, 17, 18, 21, 22, 24, 25, 27, 29, 31,
32, 34, 35, 36, 38, 45, 46, 48, 55, 4, 5, 6, 8, 9, 10, 11, 12,
13, 17, 18, 21, 22, 24, 25, 27, 29, 31, 32, 34, 35, 36, 38, 45,
46, 48, 55, 4, 5, 6, 8, 9, 10, 11, 12, 13, 17, 18, 21, 22, 24,
25, 27, 29, 31, 32, 34, 35, 36, 38, 45, 46, 48, 55, 4, 5, 6,
8, 9, 10, 11, 12, 13, 17, 18, 21, 22, 24, 25, 27, 29, 31, 32,
34, 35, 36, 38, 45, 46, 48, 55, 4, 5, 6, 8, 9, 10, 11, 12, 13,
17, 18, 21, 22, 24, 25, 27, 29, 31, 32, 34, 35, 36, 38, 45, 46,
48, 55), priceIndex = c(8L, 16L, 25L, 27L, 2L, 24L, 18L, 26L,
26L, 26L, 20L, 15L, 1L, 10L, 30L, 11L, 12L, 18L, 17L, 23L, 23L,
6L, 1L, 5L, 24L, 7L, 10L, 22L, 7L, 20L, 8L, 10L, 2L, 30L, 16L,
27L, 21L, 14L, 21L, 13L, 16L, 11L, 11L, 7L, 22L, 21L, 30L, 2L,
19L, 2L, 10L, 17L, 6L, 12L, 5L, 30L, 12L, 15L, 29L, 19L, 16L,
16L, 22L, 9L, 10L, 9L, 10L, 19L, 22L, 6L, 16L, 24L, 25L, 24L,
12L, 10L, 26L, 12L, 30L, 16L, 9L, 5L, 8L, 7L, 2L, 4L, 9L, 11L,
16L, 10L, 13L, 23L, 1L, 10L, 9L, 10L, 2L, 17L, 6L, 15L, 5L, 18L,
2L, 2L, 13L, 9L, 18L, 10L, 25L, 8L, 26L, 29L, 14L, 3L, 12L, 22L,
15L, 22L, 14L, 13L, 27L, 4L, 16L, 20L, 12L, 19L, 12L, 20L, 12L,
17L, 9L, 1L, 28L, 23L, 24L, 13L, 16L, 10L, 21L, 1L, 18L, 15L,
1L, 15L, 23L, 5L, 16L, 27L, 8L, 7L, 5L, 20L, 3L, 3L, 7L, 3L,
23L, 1L, 26L, 4L, 5L, 18L, 13L, 17L, 30L, 22L, 14L, 29L, 1L,
1L, 23L, 12L, 14L, 21L, 29L, 2L, 2L, 16L, 21L, 15L, 11L, 29L,
26L, 26L, 17L, 20L, 23L, 27L, 7L), totalWeight = c(0.964679717852504,
0.910153114749701, 0.937533258307128, 0.908932907218257, 0.897870703904312,
0.570664114467063, 0.793595725333603, 0.960149778439218, 0.702012263867207,
0.959840103392019, 0.942220302688495, 0.964136166436202, 0.945368646478464,
0.899686521142446, 0.874686707751765, 0.914447566897194, 0.952932668846809,
0.960061052199137, 0.926259918197789, 0.885837510813906, 0.901475780845684,
0.779591446248175, 0.604818428169235, 0.941410295398351, 0.908944873195851,
0.940822410107144, 0.820433580971128, 0.955543163510268, 0.914685040312209,
0.948635424851211, 0.946104114649245, 0.932230610899134, 0.558057546499175,
0.750564479296488, 0.971764930983387, 0.68817373783927, 0.975097771312425,
0.962368976746048, 0.970230629172812, 0.953507602894619, 0.892296298593537,
0.930726885101312, 0.908546595974175, 0.962179609608759, 0.96839162884849,
0.935106841280912, 0.897095564773418, 0.920053661608378, 0.820365371424697,
0.646532974396383, 0.944743562870499, 0.911857926468439, 0.963635866793497,
0.944584511990913, 0.973319999879543, 0.912794288563832, 0.950505538487169,
0.947587097715066, 0.932230610899134, 0.585877063357753, 0.741854702451495,
0.974829401211451, 0.691439730628336, 0.975813815364686, 0.960835846736876,
0.961274083799183, 0.959334487143946, 0.89688427237274, 0.937723734431402,
0.912751255497468, 0.971245010442592, 0.971456099076554, 0.941243932527261,
0.898677051935661, 0.909199996904926, 0.904176820031607, 0.660962686468937,
0.926016809434945, 0.927065572055749, 0.969462751042824, 0.887911658008384,
0.974754164229651, 0.885875391195578, 0.958515313970186, 0.948823953012966,
0.936466604521389, 0.613240721391053, 0.777793767761539, 0.981209274133896,
0.706831562657967, 0.982459601639192, 0.969382100794866, 0.970450010303705,
0.960978075054578, 0.902842393873445, 0.942890887235305, 0.905145032941613,
0.985616404521002, 0.974335897510718, 0.94236227101429, 0.92257155375435,
0.903566344156375, 0.905142965998554, 0.661175613077282, 0.948470597079574,
0.937249077110803, 0.972342549476988, 0.966932959536049, 0.969719582376951,
0.892634342170433, 0.964670562454497, 0.951929452222193, 0.93649537248916,
0.612101928212217, 0.724332887315945, 0.980582527341166, 0.712928614791972,
0.987189573702774, 0.974718254899991, 0.975852766090469, 0.96236303821044,
0.899854848145425, 0.946343691677045, 0.911796075815032, 0.981805900102976,
0.97572086066658, 0.940776475282425, 0.920956214063409, 0.918314213645145,
0.909966039838214, 0.688692601749395, 0.939834970965504, 0.938634040266665,
0.97372751263285, 0.96841594260187, 0.965125603615924, 0.872094653176646,
0.974957711538891, 0.972050595493474, 0.933488903015909, 0.664724768281132,
0.725532855017458, 0.982136493351554, 0.731583789519918, 0.986998917423862,
0.985672785517343, 0.985359985268326, 0.96327016977471, 0.907456559706999,
0.947841526350148, 0.924724066870382, 0.984805872685194, 0.974845207727776,
0.956650623685199, 0.927323325078334, 0.928141500916387, 0.912472003821784,
0.718170802590407, 0.935947208560755, 0.946217508856548, 0.975281478643238,
0.969969908612259, 0.97439813803871, 0.849645214769615, 0.971427658757611,
0.972050595493474, 0.927830874535962, 0.655478629719111, 0.734298949581601,
0.984919482876493, 0.737396852851197, 0.988375665649713, 0.978252656267413,
0.978204861100427, 0.961122141972513, 0.941660644201143, 0.953036993924037,
0.925681643545421, 0.990001340259083, 0.969788001954067, 0.94817860131528,
0.928318571162957, 0.927885380703944, 0.913542321320878, 0.825157348433747,
0.948727363244703, 0.948225380163735, 0.975281478643238, 0.971354871768121
), taxIndex = c(14L, 4L, 4L, 19L, 15L, 18L, 12L, 12L, 14L, 7L,
10L, 28L, 29L, 30L, 14L, 3L, 23L, 10L, 26L, 15L, 26L, 21L, 29L,
4L, 22L, 23L, 16L, 5L, 4L, 25L, 7L, 6L, 10L, 16L, 25L, 6L, 13L,
25L, 18L, 7L, 14L, 27L, 27L, 17L, 6L, 4L, 18L, 10L, 19L, 18L,
14L, 12L, 19L, 21L, 23L, 5L, 6L, 28L, 28L, 21L, 10L, 30L, 18L,
23L, 24L, 25L, 19L, 13L, 22L, 14L, 11L, 2L, 13L, 24L, 8L, 30L,
12L, 13L, 4L, 3L, 1L, 21L, 7L, 8L, 30L, 3L, 7L, 14L, 10L, 23L,
24L, 17L, 11L, 27L, 18L, 4L, 9L, 14L, 29L, 25L, 4L, 8L, 16L,
3L, 28L, 2L, 2L, 28L, 28L, 5L, 7L, 30L, 30L, 6L, 24L, 1L, 28L,
19L, 3L, 2L, 5L, 14L, 23L, 13L, 14L, 23L, 21L, 23L, 14L, 20L,
21L, 25L, 27L, 30L, 5L, 15L, 27L, 3L, 4L, 15L, 1L, 12L, 9L, 17L,
24L, 26L, 1L, 25L, 6L, 13L, 11L, 18L, 28L, 30L, 3L, 28L, 8L,
11L, 11L, 8L, 25L, 11L, 4L, 20L, 1L, 14L, 3L, 15L, 2L, 11L, 1L,
17L, 30L, 15L, 21L, 14L, 29L, 26L, 1L, 27L, 18L, 12L, 7L, 17L,
4L, 30L, 23L, 1L, 27L), total_units = c(30L, 12L, 16L, 10L, 30L,
6L, 8L, 24L, 15L, 6L, 6L, 16L, 15L, 19L, 28L, 16L, 7L, 13L, 12L,
21L, 9L, 9L, 10L, 4L, 12L, 21L, 30L, 1L, 26L, 7L, 2L, 7L, 1L,
2L, 15L, 14L, 11L, 28L, 29L, 2L, 22L, 26L, 9L, 21L, 8L, 26L,
4L, 14L, 18L, 15L, 18L, 11L, 9L, 20L, 3L, 20L, 20L, 24L, 1L,
9L, 16L, 27L, 29L, 2L, 25L, 16L, 24L, 13L, 11L, 13L, 1L, 19L,
5L, 5L, 11L, 22L, 16L, 20L, 21L, 2L, 9L, 13L, 15L, 6L, 12L, 28L,
7L, 24L, 22L, 24L, 21L, 14L, 1L, 6L, 10L, 10L, 26L, 26L, 3L,
9L, 16L, 30L, 16L, 23L, 20L, 11L, 17L, 16L, 15L, 8L, 20L, 21L,
1L, 19L, 4L, 4L, 26L, 21L, 18L, 18L, 24L, 8L, 17L, 15L, 20L,
19L, 10L, 19L, 23L, 4L, 17L, 1L, 20L, 29L, 28L, 26L, 2L, 17L,
22L, 17L, 17L, 14L, 17L, 13L, 1L, 3L, 15L, 5L, 30L, 27L, 20L,
10L, 3L, 24L, 28L, 22L, 28L, 20L, 15L, 16L, 10L, 11L, 28L, 27L,
12L, 5L, 19L, 11L, 15L, 26L, 15L, 27L, 6L, 25L, 7L, 8L, 29L,
26L, 16L, 25L, 28L, 22L, 20L, 13L, 3L, 8L, 4L, 29L, 10L), time = c(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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7)), .Names = c("year",
"fips_state_code", "priceIndex", "totalWeight", "taxIndex", "total_units",
"time"), row.names = c(NA, -189L), vars = list(year), drop = TRUE, indices = list(
0:26, 27:53, 54:80, 81:107, 108:134, 135:161, 162:188), group_sizes = c(27L,
27L, 27L, 27L, 27L, 27L, 27L), biggest_group_size = 27L, labels = structure(list(
year = 2006:2012), class = "data.frame", row.names = c(NA,
-7L), vars = list(year), drop = TRUE, .Names = "year"), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
答案 0 :(得分:1)
我遇到了与其他模型类型类似的问题,而且固定效果的顺序显得很重要。
如果您只是按顺序翻转模型:
stargazer(iv5,iv4,iv2,iv1,type="text",
omit = c("fips_state_code","year","time"),
omit.labels = c("State FE?","Year FE?","State time trend?"))
您获得了正确的输出:
=======================================================================================
Dependent variable:
-------------------------------------------------------------------
log(total_units)
(1) (2) (3) (4)
---------------------------------------------------------------------------------------
log(priceIndex) 0.554 0.845 1.184 1.146
(1.064) (1.049) (1.561) (1.481)
Constant 0.041 0.342 -0.495 -0.283
(2.393) (2.619) (3.767) (3.576)
---------------------------------------------------------------------------------------
State FE? Yes Yes Yes No
Year FE? No Yes No No
State time trend? Yes No No No
---------------------------------------------------------------------------------------
Observations 189 189 189 189
R2 -0.001 -0.393 -1.130 -1.347
Adjusted R2 -0.405 -0.690 -1.487 -1.359
Residual Std. Error 1.001 (df = 134) 1.098 (df = 155) 1.332 (df = 161) 1.297 (df = 187)
=======================================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
答案 1 :(得分:0)
我根本不想打印出我的回归中使用的所有虚拟对象,这个问题困扰超过3小时,而且在这里找到它真是令人惊讶。
我尝试了弗洛里安建议的那种方法,实际上,在我的情况下,回归中出现的固定效果顺序并不重要,我在这里运行plm,下面是我的观星代码:
stargazer(cluster.matched.fixed.7,cluster.matched.fixed.2,cluster.matched.fixed.3,cluster.matched.fixed.4,
cluster.matched.fixed.5,cluster.matched.fixed.6,cluster.matched.fixed.1,title="Matched sample regression DID results",
omit.stat = c("f"),covariate.labels=c("D","D1","D2","log(ROA)","log(totalasset)","log(sales)",
"log(GM)","log(Export)","log(Leverage)"),omit = c("year"),omit.labels = c("Year FE?"))
其中回归7没有固定的效果,结果是正确的。 对我来说更有趣的是你在哪里找到omit =
c("fips_state_code","year","time"),
omit.labels = c("State FE?","Year FE?","State time trend?")
&#34> stargazer&#34;中的参数,我从R-cran打印出来的文件,但没有类似的东西。