在plm包的pgmm函数中的Lapack例程dgesv

时间:2017-12-25 17:44:55

标签: r plm

最近我遇到了一个问题,这个问题花了我很长时间才搞清楚,但最终却无法解决。我想在包pgmm中使用plm函数对包含180个国家和65个时段的横截面国家/地区数据进行GMM估算。这是我的代码:

pgmm(D_rcr ~ lag(D_rcr,1) +
                eco_cycle + I(log(Human_trend)) + 
                I(log(capital_trend)) + I(log(rtfpna)) + exp_rate + urban + 
                industry + service| plm::lag(mpk3_delta,3:6),data= data_test,
              index = c("country","year"),effect = "twoways",transformation = "ld")

数据如下:

          country year         D_rcr     eco_cycle Human_trend capital_trend    rtfpna      exp_rate  urban industry  service
1000 Burkina Faso 1999  0.0074201618  0.0295545705    4.644064     23946.998 0.8284378 -8.221149e-06 17.166 25.19151 42.19550
1001 Burkina Faso 2000 -0.0046062428 -0.0085762554    4.781708     25026.203 0.8177401 -8.013943e-06 17.844 21.52736 45.66413
1002 Burkina Faso 2001 -0.0074698958 -0.0022468581    4.942214     26203.394 0.8430429 -4.433730e-06 18.540 19.47667 43.47496
1003 Burkina Faso 2002 -0.0072339948 -0.0180040290    5.102502     27513.395 0.8564266 -4.243651e-06 19.258 17.52184 43.92530
1004 Burkina Faso 2003  0.0208224248 -0.0013267292    5.262760     28994.841 0.8928111 -4.900598e-06 19.996 21.18051 41.74380
1005 Burkina Faso 2004  0.0077643394 -0.0164384391    5.424015     30686.577 0.9057222 -5.039807e-06 20.757 21.17522 44.30414
1006 Burkina Faso 2005 -0.0162568441  0.0079704026    5.588694     32625.279 0.9540021 -6.000714e-06 21.537 17.97970 42.98950
1007 Burkina Faso 2006  0.0157383040  0.0101814490    5.759905     34843.140 0.9746150 -6.004488e-06 22.339 17.62221 45.65378
1008 Burkina Faso 2007  0.0200791048 -0.0074020766    5.940701     37366.725 0.9920313 -5.925001e-06 23.163 18.95747 48.37608
1009 Burkina Faso 2008 -0.0329526715 -0.0083514921    6.134060     40213.051 1.0026470 -6.737820e-06 23.993 16.22030 43.57783
1010 Burkina Faso 2009  0.0108550329 -0.0364106100    6.341043     43385.046 0.9904070 -5.581967e-06 24.828 19.32466 45.10181
1011 Burkina Faso 2010  0.0003792556 -0.0105232997    6.561223     46865.511 1.0080181 -3.757856e-06 25.665 23.00269 41.38044
1012 Burkina Faso 2011  0.0036570272 -0.0008078762    6.808363     50612.776 1.0000000 -1.947466e-06 26.505 27.15270 39.00203
1013 Burkina Faso 2012 -0.0133615481  0.0088997716    7.066275     54562.488 0.9885733 -4.819380e-06 27.346 24.91152 40.03299
1014 Burkina Faso 2013 -0.0124167169  0.0180233629    7.332700     58635.384 0.9726224 -4.963807e-06 28.186 20.99917 43.38722
1015 Burkina Faso 2014 -0.0093625110  0.0183559642    7.605543     62756.115 0.9531422 -2.547616e-06 29.024 20.47991 44.29216
1016      Burundi 1980 -0.0076063659 -0.0518049023    2.122768      4760.103 0.8508636 -4.026274e-05  4.339 12.61903 25.13108
1017      Burundi 1981  0.0062886770  0.0123692536    2.204532      5003.674 0.9142978 -2.922222e-05  4.503 13.41068 25.27003
1018      Burundi 1982 -0.0073451957 -0.0326804079    2.286727      5257.374 0.8792791 -3.623259e-05  4.674 15.44782 27.69609
1019      Burundi 1983 -0.0048256924 -0.0422295228    2.369051      5513.472 0.8658228 -3.508869e-05  4.850 15.50037 27.25349
1020      Burundi 1984 -0.0083655241 -0.0846945313    2.450960      5763.198 0.8221024 -3.652248e-05  5.033 13.84020 26.02882
1021      Burundi 1985  0.0062427433 -0.0081527185    2.531672      5997.500 0.8820450 -2.695840e-05  5.221 13.00197 25.46080
1022      Burundi 1986  0.0085330972 -0.0050508112    2.610223      6208.165 0.8880036 -2.122831e-05  5.417 13.51567 27.95960
1023      Burundi 1987  0.0013978951  0.0048612717    2.685521      6388.418 0.8895743 -2.379938e-05  5.620 17.12692 27.76170
1024      Burundi 1988  0.0120351151  0.0273960217    2.756473      6533.799 0.9023147 -1.564180e-05  5.830 16.66728 29.08768
1025      Burundi 1989 -0.0040708811  0.0237706740    2.822166      6643.176 0.8862884 -1.854892e-05  6.047 19.66485 26.65657
1026      Burundi 1990  0.0031577402  0.0461310277    2.882089      6718.144 0.9082311 -2.401352e-05  6.271 18.96324 25.15806
1027      Burundi 1991  0.0053723287  0.0913896512    2.944615      6763.149 0.9525304 -2.121296e-05  6.455 19.59612 26.09317
1028      Burundi 1992 -0.0006242234  0.1118378705    3.002747      6784.165 0.9633930 -2.326152e-05  6.637 21.17273 25.29381
1029      Burundi 1993 -0.0140939288  0.0566603249    3.058046      6787.775 0.8787442 -2.704195e-05  6.823 22.44800 24.93331
1030      Burundi 1994 -0.0051914045  0.0446976884    3.112606      6780.856 0.8391036 -2.185189e-05  7.014 22.47806 30.74383
1031      Burundi 1995 -0.0101237974 -0.0044596262    3.168960      6770.888 0.7683206 -2.265241e-05  7.211 19.24821 32.60719
1032      Burundi 1996 -0.0120905700 -0.0733896784    3.230019      6765.241 0.6975604 -1.365663e-05  7.412 12.63033 30.14807
1033      Burundi 1997 -0.0018359105 -0.0465258303    3.298963      6770.493 0.6909751 -9.966291e-06  7.618 15.62753 36.64545
1034      Burundi 1998  0.0010393142  0.0151532770    3.379006      6792.311 0.7113460 -1.557693e-05  7.830 15.84338 36.12517
1035      Burundi 1999 -0.0087320046  0.0148961511    3.473067      6835.203 0.6845708 -1.100638e-05  8.036 16.20578 35.90429
1036      Burundi 2000 -0.0036065995  0.0062503238    3.583363      6902.337 0.6644523 -1.597629e-05  8.246 16.93214 35.00821
1037      Burundi 2001 -0.0015909534  0.0154145281    3.715491      6997.577 0.6616966 -1.724226e-05  8.461 16.49441 37.06893
1038      Burundi 2002  0.0000723279  0.0336641982    3.865710      7124.685 0.6701715 -1.645656e-05  8.682 16.69844 37.51544
1039      Burundi 2003 -0.0081492568 -0.0184660371    4.033378      7286.589 0.6383393 -1.518514e-05  8.908 17.03472 36.60505
1040      Burundi 2004 -0.0053202507 -0.0321812288    4.217188      7484.465 0.6333758 -1.595708e-05  9.139 17.70286 36.85237
1041      Burundi 2005 -0.0073075515 -0.1193560863    4.415421      7718.514 0.5999591 -2.871464e-05  9.375 18.45308 37.05039
1042      Burundi 2006  0.0953559671 -0.1570653899    4.626188      7989.549 0.6067449 -3.880530e-05  9.617 16.71110 38.94535
1043      Burundi 2007  0.0094422379 -0.1988202659    4.847617      8298.925 0.6223342 -3.338575e-05  9.864 18.03837 44.62553
1044      Burundi 2008  0.0217479374 -0.1709468848    5.077926      8647.895 0.6832167 -3.469164e-05 10.118 15.98312 43.42593
1045      Burundi 2009  0.0516023614 -0.0108370357    5.315478      9036.445 0.8509285 -2.165262e-05 10.376 16.63140 42.83632
1046      Burundi 2010  0.0128353068  0.0302280799    5.558862      9461.720 0.9318257 -1.805687e-05 10.641 16.70423 42.84727
1047      Burundi 2011  0.0164302478  0.0549153842    5.820920      9917.799 1.0000000 -1.674949e-05 10.912 16.89924 42.75338
1048      Burundi 2012  0.0177947374  0.0834531229    6.088302     10396.854 1.0781934 -1.448994e-05 11.189 16.88556 42.53204
1049      Burundi 2013 -0.0094655827  0.0443990294    6.360665     10890.133 1.0653062 -1.141332e-05 11.472 17.73397 42.43866
1050      Burundi 2014 -0.0061952542  0.0121767175    6.637850     11389.026 1.0576664 -1.038206e-05 11.761 18.31099 42.42737

错误是

Error in solve.default(crossprod(WX, t(crossprod(WX, A1)))) : 
      Lapack routine dgesv: system is exactly singular: U[10,10] = 0

有时在调整之后,即data_test <- dplyr::filter(data_test,!is.na(rtfpna)),错误将变为:

Error in solve.default(A1) : 
  system is computationally singular: reciprocal condition number = 1.14054e-16

Error in solve.default(crossprod(WX, t(crossprod(WX, A2)))) : 
  system is computationally singular: reciprocal condition number = 1.69599e-24

我认为pgmm函数1)无法很好地处理不平衡数据帧plm函数,尤其是当数据包含10%NA时。 2)当特征值太小时,求解函数没有用于求解逆矩阵的替代。另外,据我的同事主要在Stata上工作,Stata也没有这样的问题。所以我的问题是,如何解决这个问题,我的代码是正确的方向吗?

任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:0)

从提供的数据来看,这可能会导致错误:您的数据集不平衡。看来您对布隆迪的数据始于1980年,而布基纳法索的数据始于1999年。

我有同样的错误。在我的数据集中,我有1891年到1899年,但是缺少1892年-我忘记了清理数据,因此它是平衡的。当我卸下1891年时,问题解决了。

从直觉上讲这是有道理的:Sys-GMM使用高级延迟来检测第一个延迟。但是,如果随机丢失年份,则显然不能始终如一地工作。

当然,也可能是您的解释变量中具有高度相关的var。